题意:有两个数分别是m,n,求前10组1 + 2 + ... + m-1 = m+1 + ... + n的m和n,用求和公式退出2*pow(m,2) = (n+1)*n,然后就是枚举成立的情况,当然因为数据少,也是可以打表节省时间
#include <iostream>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <cstdio>
using namespace std;
const int MAXN = 1000000000;
int main(){
long long a;
double b;
int count = 0;
for (int i = 6; i < MAXN; i++){
b = (double) i * (i+1);
b /= 2;
b = sqrt(b);
a = b;
if (a == b){
cout << setw(10) << a << setw(10) << i << endl;
++count;
}
if (count == 10)
break;
}
return 0;
}