Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // 4948-01
- //
- // Created by 박대호 on 2017. 3. 24..
- // Copyright © 2017년 박대호. All rights reserved.
- //
- // 베르트랑 공준
- #include <cstdio>
- int main(int argc, const char * argv[]) {
- int n = 0 ;
- int count = 0 ;
- int prmNumArr[246913] = { 0, } ;
- // 246912 까지 소수를 다 설정해 놓는다
- for(int i=2 ; i<=246912 ; i++){
- if(prmNumArr[i] == -1){
- continue ;
- }
- for(int j=2 ; j<=246912/i ; j++){
- prmNumArr[i*j] = -1 ;
- }
- }
- while (1) {
- scanf("%d", &n);
- if(n == 0){
- break ;
- }
- for(int i=n+1 ; i<=2*n ; i++){
- // 소수인 것들만 카운트한다
- if(prmNumArr[i] == 0){
- count++ ;
- }
- }
- printf("%d\n", count);
- count = 0 ;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement