递推+猜结论?(也不算猜的

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cctype>

using namespace std;

inline void read(long long &x)
{
    int k = 1; x = 0;
    char c = getchar();
    while (!isdigit(c))
        if (c == '-') k = - 1, c = getchar();
        else c = getchar();
    while (isdigit(c))
        x = (x << 1) + (x << 3) + (c ^ 48),
        c = getchar();
    x *= k;
}

long long T, n, cm, dp[10101];

int main()
{
    read(T);
    for (int plk = 1; plk <= T; ++plk)
    {
        read(n);
        memset(dp, 0, sizeof(dp));
        dp[0] = 0, dp[1] = 2; cm = 5;
        for (int i = 2; i <= n; ++i)
            dp[i] = dp[i - 1] + cm, cm += 4; 
        printf("%lld\n", dp[n]);
    }
    return 0;
}

 

相关文章:

  • 2022-12-23
  • 2021-12-01
  • 2021-10-20
  • 2022-12-23
  • 2022-12-23
  • 2021-07-21
猜你喜欢
  • 2022-01-22
  • 2021-12-04
  • 2021-12-26
  • 2022-01-18
  • 2021-07-09
  • 2021-09-08
相关资源
相似解决方案