HDU 3826 squarefree Number (prime) __ Number theory

Source: Internet
Author: User
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; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.