一重for loop解决,不用两重
AC Code
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n,sr;
bool flag;
while(cin>>n)
{
flag=0;
sr=pow(2*n-3,0.5);
for(int i=1;i<=sr;i++)
{
int k=pow(2*n-i*(i+1),0.5);
//do not neglect "k>0"
if(k && k*(k+1)+i*(i+1)==2*n)
{
flag=1;
break;
}
}
if(flag) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}