Shu_1746 no square factor

Source: Internet
Author: User

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;}


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.