fork download
  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4. while(1){
  5. int n; cin >> n;
  6. if(n==0){
  7. return 0;
  8. }
  9. else if(n==1){
  10. cout << 1;
  11. }
  12. else{
  13. int list[1000002]={};
  14. for(int x=2; x<=2*n; x++){
  15. for(int i=x+x; i<=n; i+=x){
  16. if(list[i]!=1){
  17. list[i]=1;
  18. }
  19. }
  20. }
  21. list[1]=1;
  22. int i=0, ans[1000002]={};
  23. for(int x=n; x<=2*n; x++){
  24. if(list[x]==0) i++;
  25. }
  26. cout << i << "\n";
  27. }
  28. }
  29. }
Success #stdin #stdout 0s 7500KB
stdin
1
10
13
100
1000
10000
100000
0
stdout
110
14
100
1000
10000
100000