Http: // 202.121.199.212/judgeonline/problem. php? Id = 1746
Analy: There is no square factor, that is, the number of different prime factors must not exceed 1, so we will work in this direction:
Calculate all the prime numbers between 2-10 ^ 9 (that is, all the prime numbers between 99999989 and are listed in the bool table)
Then, one prime factor is used to judge the past;
Then, it was decisive that the TLE was performed n times;
So I looked at other people's submission records and found that the code was very short, and the table could not be made. The time was also very short. Is there a good algorithm?
After the test, I found relevant information without square factors and did not find a good algorithm;
So, it's violent...
Then, AC...
Tip:
Remove int (I * I) with N of long, and there is an error in Division 0 (on OJ, there is no error reported on the local machine)
Code:
#include <iostream>#include <stdio.h>#include <string>#include <string.h>using namespace std;int main(){ // freopen("in5.txt","r",stdin); //freopen("out.txt","w",stdout); int t; long long n; bool flag; scanf("%d",&t); for(int cno=1;cno<=t;cno++){ scanf("%lld",&n); printf("Case %d: ",cno); if(n%100==0){ printf("No\n"); continue; } flag=false; for(long long i=2;i*i<=n;i++){ if(n%(i*i)==0){ printf("No\n"); flag=true; break; } } if(!flag) printf("Yes\n"); } return 0;}