Article From:https://www.cnblogs.com/shixinzei/p/9062324.html

Title Link: https://www.51nod.com/onlineJudge/questionCode.html#! ProblemId=1240

Ideas:From 2 to the sqrt (n) query can eliminate his prime number, and judge whether the square of the prime number can be divided into N, if you can output 0, otherwise it can be judged to divide his prime number, odd output -1, and even number output 1

 

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<string>
 4 #include<cstring>
 5 #include<cmath>
 6 using namespace std;
 7 int main()
 8 {
 9     std::ios::sync_with_stdio(false);
10     int n;
11     cin>>n;
12     int flag=0,prime=1;
13     for(int i=2;i<=sqrt(n);i++){
14         if(n%i==0){
15             prime++;
16             n/=i;
17             if(n%i==0){
18                 flag=1;
19                 break;
20             }
21         }
22         if(flag) break;
23     }
24     if(flag) cout<<0<<endl;
25     else{
26         if(prime%2==1) cout<<-1<<endl;
27         else cout<<1<<endl;
28     }
29     return 0;
30 }

 

Similar Posts:

Link of this Article: 51Nod 1240 Mobius function

Leave a Reply

Your email address will not be published. Required fields are marked *