Advertisement
erfanul007

Uva 11246

Sep 16th, 2021
763
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long int
  5.  
  6. const int N = 1000000000;
  7.  
  8. bool mark[N+1];
  9.  
  10. int main(){
  11.     #ifdef ERFANUL007
  12.         clock_t tStart = clock();
  13.         freopen("input.txt", "r", stdin);
  14.         freopen("output.txt", "w", stdout);
  15.     #endif
  16.  
  17.     int t; cin >> t;
  18.  
  19.     while(t--){
  20.         int n, k;
  21.         cin >> n >> k;
  22.        
  23.         for(int i=1; i<=n; i++) mark[i] = 1;
  24.            
  25.         for(int i=1; i<=n/k; i++){
  26.             if(mark[i]) mark[i*k] = 0;
  27.         }
  28.         int ans = 0;
  29.         for(int i=1; i<=n; i++){
  30.             if(mark[i]) ans++;
  31.         }
  32.         cout << ans << '\n';
  33.  
  34.         for(int i=1; i<=n; i++) mark[i] = 0;
  35.     }
  36.  
  37.     #ifdef ERFANUL007
  38.         fprintf(stderr, ">>> Runtime : %.9f\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
  39.     #endif
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement