ahamed210

almost_prime1

Apr 10th, 2021
913
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int fact(int n)
  5. {
  6.     int p = 0;
  7.     for(int i = 2; i*i <= n; i++)
  8.     {
  9.         if(n%i == 0)
  10.         {
  11.             p++;
  12.             while(n%i == 0) n/=i;
  13.         }
  14.     }
  15.     if(n > 1) p++;
  16.     return p;
  17. }
  18.  
  19. int main()
  20. {
  21.     int n, p = 0;
  22.     cin >> n;
  23.     if(n < 6) cout << 0 << endl;
  24.     else if(n >= 6 && n <= 10) cout << 2 << endl;
  25.     else{
  26.         for(int i = 11; i <= n; i++){
  27.             if(fact(i) >= 2) p++;
  28.         }
  29.         cout << p+2 << endl;
  30.     }
  31.     return 0;
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment