Description
In mathematics, a squarefree number is one which are divisible by no perfect squares, except 1. For example, Square-free but, as it is divisible by 9 = 3^2. Now you are need to determine whether an integer is Squarefree or.
Input
The ' The ' contains an integer T indicating the number of test cases.
For each test case, the there is a single line contains an integer N.
Technical Specification 1 <= T <= 2 <= N <= 10^18
Output
For each test case, output the case number A. Then output "Yes" If N is Squarefree, "No" otherwise.
Sample Input
2
75
Sample Output
Case 1:yes Case
2:no
the
To determine whether a number is "no square number" (Is this translation?) )
train of Thought
Obviously the data range of 1018 10^{18} does not allow us to try each.
Considering the decomposition of N to mass factor, we know that if a prime number is greater than 2, it means that it is not a square number.
After the screening of all the 10^6 below 106, if n>106 n>10^6, it means that it contains up to two 106 10^6 above the quality factor, and then squared to determine whether the two qualitative factors are the same.
AC Code
#include <bits/stdc++.h> using namespace std; typedef __int64 LL; const int MAXN = 1E6+10;
BOOL VISIT[MAXN];
int PRIME[MAXN];
int tot;
LL N;
void Getprime () {tot=0;
memset (visit,0,sizeof (visit));
for (int i=2; i<maxn; i++) {if (!visit[i)) {prime[tot++]=i;
for (int j=i+i; j<maxn; j+=i) visit[j]=1; BOOL Solve () {for (int i=0; i<tot; i++) {if (n%prime[i]==0) {n/=prime[i
];
if (n%prime[i]==0) return false;
} if (n>=1e6) {LL tmp = sqrt (n) + 0.5;
if (tmp*tmp==n) return false;
return true;
int main () {getprime ();
int T;
cin>>t;
for (int ti=1; ti<=t; ti++) {cin>>n;
cout<< "Case" <<ti<< ":"; cout<< (Solve ()? "
Yes ":" No ") <<endl;
return 0; }