题意:就是从n到1再从1到n的各个数字之和为sum1, 然后从n到m,再从m到n的各个数字之和为sum2,求,(n,m)的前10组解。
思路: 直接建模,利用等差数列的求和公式计算一个公式(2n+1)^2 - m^2=1; 然后直接佩尔方程式即可!
#include<cstdio> #include<cmath> #define ll long long int main() { int x, y, x1, y1, px, py; x1 = 3; y1 = 1; px = 3; py = 1; for (int i = 0; i < 10; ++i) { x = px*x1 + 8 * py*y1; y = py*x1 + px*y1; printf("%10d%10d ", y, (x - 1) / 2); px = x; py = y; } }
#include<cstdio> #include<cmath> #define ll long long int main() { int x, y, x1, y1, px, py; x1 = 3; y1 = 1; px = 3; py = 1; for (int i = 0; i < 10; ++i) { x = px*x1 + 8 * py*y1; y = py*x1 + px*y1; printf("%10d%10d ", y, (x - 1) / 2); px = x; py = y; } }
#include<cstdio> #include<cmath> #define ll long long int main() { int x, y, x1, y1, px, py; x1 = 3; y1 = 1; px = 3; py = 1; for (int i = 0; i < 10; ++i) { x = px*x1 + 8 * py*y1; y = py*x1 + px*y1; printf("%10d%10d ", y, (x - 1) / 2); px = x; py = y; } }