http://codeforces.com/contest/716/problem/C
题目大意:感觉这道题还是好懂得吧。
思路:不断的通过列式子的出来了。首先我们定义level=i, uplevel = i + 1,目前的uplevel,然后我们可以知道,之前求出来的restgrade%level = 0,于是我们可以列出一个式子sqrt(k1 * i + grade) = uplevel * k.因为grade也是i的倍数,假定grade = k2 * i,所以我们写成sqrt((k1 + k2) * i) = uplevel * k,所以两边平方再移项以后就可以发现总有这样的一个解满足条件,即:k1 = level * uplevel * uplevel - k2。然后我们打表一下:
//看看会不会爆int!数组会不会少了一维! //取物问题一定要小心先手胜利的条件 #include <bits/stdc++.h> using namespace std; #define LL long long #define ALL(a) a.begin(), a.end() #define pb push_back #define mk make_pair #define fi first #define se second #define haha printf("haha ") int main(){ LL n; LL level = 1, grade = 2; LL k1, k2, k; scanf("%I64d", &n); for (LL uplevel = 2; uplevel <= n + 1; uplevel++){ k2 = grade / level; ///printf("k2 = %I64d ", k2); k1 = level * uplevel * uplevel - k2; grade = sqrt((k1 + k2) * level); ///printf("grade = %I64d %I64d %I64d ", grade, grade / level , uplevel); level++; printf("%I64d ", k1); } return 0; }
我们发现grade总等于level * uplevel,所以我们就可以求得level,然后看到level=1的时候不满足条件,然后特判一下就好了
//看看会不会爆int!数组会不会少了一维! //取物问题一定要小心先手胜利的条件 #include <bits/stdc++.h> using namespace std; #define LL long long #define ALL(a) a.begin(), a.end() #define pb push_back #define mk make_pair #define fi first #define se second #define haha printf("haha ") int main(){ LL n; LL level = 1, grade = 2; LL k1, k2, k; scanf("%I64d", &n); cout << 2 << endl; for (LL i = 2; i <= n; i++){ printf("%I64d ", (i + 1) * (i + 1) * i - i + 1); } return 0; }