使用sqrt函数模拟。
1 typedef long long LL; 2 class Solution { 3 public: 4 bool judgeSquareSum(int c) { 5 for(LL i=0;i*i<=c;i++){ 6 LL a_2=i*i; 7 LL b_2=c-a_2; 8 double b=sqrt(b_2); 9 if(b-(LL)b<=1e-9){ 10 return true; 11 } 12 } 13 return false; 14 } 15 };