Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. //
  2. // main.cpp
  3. // 4948-01
  4. //
  5. // Created by 박대호 on 2017. 3. 24..
  6. // Copyright © 2017년 박대호. All rights reserved.
  7. //
  8. // 베르트랑 공준
  9.  
  10. #include <cstdio>
  11.  
  12. int main(int argc, const char * argv[]) {
  13.  
  14.  
  15. int n = 0 ;
  16. int count = 0 ;
  17. int prmNumArr[246913] = { 0, } ;
  18.  
  19. // 246912 까지 소수를 다 설정해 놓는다
  20. for(int i=2 ; i<=246912 ; i++){
  21.  
  22. if(prmNumArr[i] == -1){
  23. continue ;
  24. }
  25.  
  26. for(int j=2 ; j<=246912/i ; j++){
  27. prmNumArr[i*j] = -1 ;
  28. }
  29. }
  30.  
  31. while (1) {
  32.  
  33. scanf("%d", &n);
  34.  
  35. if(n == 0){
  36. break ;
  37. }
  38.  
  39. for(int i=n+1 ; i<=2*n ; i++){
  40. // 소수인 것들만 카운트한다
  41. if(prmNumArr[i] == 0){
  42. count++ ;
  43. }
  44. }
  45.  
  46. printf("%d\n", count);
  47. count = 0 ;
  48. }
  49.  
  50.  
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement