YEZAELP

TOI10: จำนวนเฉพาะ (Prime)

Dec 29th, 2020 (edited)
87
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int qs[10000001];
  6. vector <bool> prime(10000001, true);
  7.  
  8. int main(){
  9.  
  10.     int n;
  11.     scanf("%d", &n);
  12.  
  13.     for(int i = 2; i <= 10000000; i ++){
  14.         if(prime[i]){
  15.             for(int j = i + i; j <= 10000000; j = j + i){
  16.                 prime[j] = false;
  17.             }
  18.         }
  19.         qs[i] = qs[i-1] + prime[i];
  20.         if(qs[i] == n){
  21.             printf("%d", i);
  22.             return 0;
  23.         }
  24.     }
  25.  
  26.     return 0;
  27. }
  28.  
RAW Paste Data Copied