1 #include<iostream> 2 #include<math.h> 3 using namespace std; 4 int main() 5 { 6 int a[50]; 7 int times,peg; 8 int n=1; 9 int num=1; 10 int i=0; 11 int j; 12 while(cin>>times) 13 { 14 while(times--) 15 { 16 cin>>peg; 17 memset(a,0,sizeof(a)); 18 while(1) 19 { 20 if(i==peg) 21 { 22 cout<<num-1<<endl; 23 break; 24 } 25 if(a[i]==0) 26 { 27 a[i]=num++; 28 i=0; 29 continue; 30 } 31 else 32 { 33 j=sqrt(a[i]+num); 34 if(j*j==(a[i]+num)) 35 { 36 a[i]=num++; 37 i=0; 38 continue; 39 } 40 else 41 { 42 i++; 43 } 44 } 45 } 46 } 47 } 48 return 0; 49 }
时间: 2024-10-10 20:45:54