看的題解,感受都很差說什麼,,ios
可是聽說這個題是某年河南省,一我的都沒正解?spa
數學仍是太弱,code
感受這個題仍是經過數學推導,強行將枚舉範圍縮小縮小小。。。blog
1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <iostream> 5 #include <algorithm> 6 using namespace std; 7 typedef long long LL; 8 LL gcd(LL a,LL b){return b?gcd(b,a%b):a;} 9 LL sqr(LL x){return x*x;} 10 int ans; 11 void cal(LL x){ 12 for(LL i = 1;i*i<x;++i){ 13 LL y = x-i*i,z = sqrt(y); 14 if(z*z!=y)continue; 15 if(i>=z)continue; 16 if(gcd(i*i,y)==1)ans++; 17 } 18 } 19 int main() 20 { 21 LL n;cin>>n;n*=2; 22 ans = 0; 23 for(LL i = 1;i*i<=n;++i){ 24 if(i*i==n){cal(i);continue;} 25 if(n%i==0){ 26 cal(i);cal(n/i); 27 } 28 } 29 cout<<(ans+1)*4<<endl; 30 return 0; 31 }