prime_number
C
#include <stdio.h>
int main() {
int arr[246913] ={0,};
for (int i = 2; i <= 123456; i++){
for (int j = 2; j*i <= 246912; j++ ) {
arr[j*i] = 1;
}
}
while (1) {
int n, cnt = 0; scanf("%d",&n);
if(n <= 0) break;
for (int i = n+1; i <= 2*n; i++)
if (arr[i] == 0) cnt++;
printf("%d\n",cnt);
}
return 0;
}
Output
Embed on website
To embed this program on your website, copy the following code and paste it into your website's HTML:
Comments
This comment belongs to a banned user and is only visible to admins.
This comment belongs to a deleted user and is only visible to admins.