注意整型长度即可。
1 #include <iostream> 2 #include <math.h> 3 using namespace std; 4 5 int main(){ 6 long a, b, c, d; 7 bool flag = false, zong = false; 8 cin >> a >> b; 9 for(int i=a; i<=b; i++){ 10 c = pow(i, 3) - pow(i-1, 3); 11 d = sqrt(c); 12 long j; 13 if(c % d == 0){ 14 for(j = 1; j*j*2 < d; j++){ 15 if(pow(j+1, 2) + pow(j, 2) == d){ 16 flag = true; 17 break; 18 } 19 } 20 } 21 if(flag){ 22 cout << i << " " << j+1 << endl; 23 zong = true; 24 flag = false; 25 } 26 } 27 if(!zong) cout << "No Solution" << endl; 28 return 0; 29 }
浙公网安备 33010602011771号