2 solutions
-
2
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll N=1e6+7; ll n; int vis[N],prime[N]; void sieve(ll n) { int k=0; memset(vis,0,sizeof(vis));//清零 vis[0]=vis[1]=1; for(int i=2;i<=n;i++) { if(vis[i]==0) prime[k++]=i; for(int j=0;j<k;j++) { if(i*prime[j]>n)//倍增结果超出范围,退出 break; vis[i*prime[j]]=1;//将倍增结果进行标记 if(i%prime[j]==0)//i是前面某个素数的倍数时,退出 break; } } } int main() { sieve(N); while(~scanf("%lld",&n)) { if(vis[n]==0)printf("Yes\n"); else printf("No\n"); } return 0; }
Information
- ID
- 327
- Time
- 55ms
- Memory
- 256MiB
- Difficulty
- 8
- Tags
- # Submissions
- 603
- Accepted
- 70
- Uploaded By