9 solutions
-
0
#include<stdio.h> int box[1000000+5]; const int N=1e6+5; void primes(){ box[0]=1; box[1]=1; for(int i=2;i<=N;i++){ if(box[i]==0){ for(long long j=i;j*i<=N;j++){ box[i*j]=1; } } } } int main() { int n; scanf("%d",&n); primes(); while(n--){ int m; scanf("%d",&m); int cnt=0; for(int i=2;i<=m;i++){ if((box[i]==0&&box[i-2]==0)||(box[i]==0&&box[i-1]==0)){ cnt++; } } printf("%d\n",cnt); } return 0; }
Information
- ID
- 128
- Time
- 3000ms
- Memory
- 128MiB
- Difficulty
- 8
- Tags
- (None)
- # Submissions
- 1929
- Accepted
- 270
- Uploaded By