1004 Quality Square number
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)Problem Description Xiaoming is naturally sensitive to the number, 3-year-old can recite pi 100 digits.
Now, Xiaoming slowly grew up, but still very like the number, recently, he was fascinated with prime numbers and the square number, and his own prime number of the square named "Quality Square."
Now he is working on the question of how much of the nearest mass is to a positive integer n.
Input input data The first line is a positive integer t (t<=20), which indicates that there is a T-group input data.
Next T line, enter a positive integer N (1<=n<=10^8) per line.
Output for each set of data, please export the closest to the number of the mass square, each set of output in one row.
Sample Input
2 1 10
Sample Output
4 9
#include <iostream> #include <cmath> using namespace std; #define MAX 10000 int a[max+1]= {
1,1,0}; int main () {for (int i=2; i<=5000; i++) for (int j=i<<1; j<max+1; j+=i) {A
[J]=1;
} int T;
int N;
cin>>t;
while (t--) {cin>>n;
int temp=sqrt (N);
if (temp*temp = = N && a[temp]==0) cout<<n<<endl;
else if (temp==1) cout<<4<<endl;
else {int I, J;
For (I=temp, i>=2; i--) {if (a[i]==0) break;
For (j=temp+1 j<=max; j + +) {if (a[j]==0) break;
} if (N-i*i <= j*j-n) cout<<i*i<<endl;
else cout<<j*j<<endl; }
}
}
Always looking at once space in a daze, those who say not separate friends, turn around, strangers. Familiar, quiet, quiet, left, left, unfamiliar, unfamiliar, disappeared, disappeared, strangers.