记得暑假时写这道题时没写出来,,纠结了好久,一直超时,,这次写这道题,,花了一个小时ac了,,,,这算是进步了??????题目:
2 6 10 25 65
4 0 8 12 16HintFor the fourth test case, (A,B) can be (0,5), (0,-5), (5,0), (-5,0), (3,4), (3,-4), (-3,4), (-3,-4), (4,3) , (4,-3), (-4,3), (-4,-3)
#include <iostream> #include <cstdio> #include <string.h> #include <string> #include <cmath> using namespace std; class countn{ public: /*countn(int x){ num=x; }*/ void calculate(); void setvalue(int x); private: int num; }; void countn::setvalue(int x){ num=x; } void countn::calculate(){ int flag[100010]; memset(flag,0,sizeof(flag)); int xx=0; int yy=(int)sqrt((double)num); for(int i=0;i<=yy;++i){ //flag[i]=1; int y=num-i*i; int newy=sqrt((double)y); if(flag[i]==1&&flag[newy]==1&&i!=newy) continue; flag[newy]=1; flag[i]=1; if(newy*newy+i*i==num){ if(newy&&i&&newy!=i){ xx+=8; } else{ xx+=4; } } } printf("%d\n",xx); } int main(){ //freopen("1.txt","r",stdin); int n; countn mycountn; while(scanf("%d",&n)!=EOF){ mycountn.setvalue(n); mycountn.calculate(); } return 0; }