2 solutions
-
0
#include <stdio.h> int isprime(int x) { int n = sqrt(x); for(int i = 2; i <= n; i++){ if(x % i == 0) return 0; } return 1; } int main() { int n; while(~scanf("%d",&n)) { if(n < 2) printf("No\n"); else{ if(isprime(n)) printf("Yes\n"); else printf("No\n"); } } return 0; }
-
0
埃式筛 #include<bits/stdc++.h> using namespace std; bool vis[10000005]={true,true}; int main(){ unsigned long long n; for(int i=2;i*i<=10000005;i++){ if(!vis[i]){ for(unsigned long long j=i*2;j<=10000005;j+=i){ vis[j]=true; } } } while(cin>>n){ if(!vis[n]){ cout<<"Yes"<<endl; } else{ cout<<"No"<<endl; } } return 0; }
- 1
Information
- ID
- 326
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 6
- Tags
- # Submissions
- 157
- Accepted
- 50
- Uploaded By