题意:寻找10对整数(m , n)满足,从1加到m - 1 等于 m + 1加到 n。
题解:直接推出公式 m = sqrt((n * (n + 1)) / 2)。然后如果m是整数说明满足条件。
#include <stdio.h>
#include <string.h>
#include <math.h>
const int N = 100000000;
int main() {
for (int i = 2; i <= N; i++) {
double j = (double)i;
double temp1 = sqrt(j * (j + 1) / 2);
int temp2 = temp1;
if (temp1 - temp2 < 1e-9)
printf("%10d%10d\n", temp2, i);
}
return 0;
}