C. Plus and Square Root (构造)

  1. 题目链接:http://codeforces.com/contest/716/problem/C
  2. 题意:
    1. `设当前层数为k,屏幕上的数为x,对一个数有两种操作:
      1. 加号:使这个数加上当前层数,即 x+=k
      2. 根号:对x求2次根,并且层数k++。这个操作只有当x是完全平方数时才能操作。即x=m×m。
    2. 第一个数为2,在第一层。要求进行n次操作,使层数到达n+1层。设执行根号后的数为m,执行根号后的层数为k, 则 必须满足 m%k==0。
    3. 输出若要达到n+1层,每次执行根号操作前,需要进行的加号操作的次数。
  3. 算法:构造
  4. 思路:题意可转化为求每层执行全部加号操作后的数。设第i层执行全部加号后的数为ai,则题目条件可以转化为:
    1. a[i+1] ≡ 根号(a[i]) (mod (i+1))
    2. a[i+1] >= 根号(a[i])
    3. 根号(a[i]) % i == 0
    4. 因此,可以令a[i] = [i*(i+1)]的平方
      所以每一层要输出的数为(a[i] - 根号(a[i-1]) )/i = i*(i+1)*(i+1) - i; 但是在第一层时直接输出2

#include <bits/stdc++.h>
#define pi acos(-1)
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const LL LL_INF = 1LL<<62;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;



int main()
{
    int n; scanf("%d", &n);
    for(int i=1; i<=n; i++){
        if(i==1) printf("2\n");
        else printf("%I64d\n", (LL)i*(i+1)*(i+1) - (LL)(i-1));
    }
}

猜你喜欢

转载自blog.csdn.net/qq_37352710/article/details/81167167