Problem Description Xiaoming is naturally sensitive to numbers, and can recite pi 100 when he is 3 years old.
Now, Xiaoming slowly grew up, but still like the numbers, recently, he was fascinated by prime numbers and squares, and he named the square of the prime number as "qualitative square."
Now he's working on the question: what is the closest mass to a positive integer n?
Input data The first line is a positive integer t (t<=20), which indicates that there is a T group of input data.
Next T line, enter a positive integer N (1<=n<=10^8) per line.
Output for each set of data, outputs the nearest mass of N, one row for each set of outputs.
Sample Input2110
Sample Output49
Water out of the national freshman race, I just want to say that at that time test instructions understand wrong.
Yu Min's code:
1#include <iostream>2#include <algorithm>3#include <iomanip>4#include <string>5#include <cstring>6#include <cmath>7 using namespacestd;8 intcmpintx)9 {Ten if(x==1)return 0; One Else A { - for(intI=2; i<=sqrt (x); i++) - if(x%i==0)return 0; the } - return 1; - } - intMain () + { - intn,m,i,j,k,t; +Cin>>T; A while(t--) at { -Cin>>m; -k=sqrt (m); - if(m==1|| m==2|| m==3) -cout<<"4"<<Endl; - Else in{intK; - for(i=m;; i++) to{k=sqrt (i); + if(K*K==I&&CMP (k)) Break; - } the for(j=m;; j--) *{k=sqrt (j); $ if(K*K==J&&CMP (k)) Break;Panax Notoginseng } - the if(I-M<M-J) cout<<i<<Endl; + Elsecout<<j<<Endl; A } the } + return 0; -}
View Code
HDU number of qualitative square