hopingsteam

Untitled

Sep 19th, 2020
889
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. ifstream fin("prim013.in");
  4. ofstream fout("prim013.out");
  5. int prim(int n)
  6. {
  7.     if(n == 0 || n == 1) return 0;
  8.     if(n == 2) return 1;
  9.     if(n % 2 == 0) return 0;
  10.     for(int i = 3 ; i * i <= n ; i += 2) if(n % i == 0) return 0;
  11.     return 1;
  12. }
  13. int nrdiv(int n)
  14. {
  15.     int d = 2 , prod = 1;
  16.     while(n > 1)
  17.     {
  18.         int p = 0;
  19.         while(n % d == 0) {n /= d; p++;}
  20.         if(p) prod = prod * (p+1);
  21.         d++;
  22.         if(d * d > n) d =n;
  23.     }
  24.     return prod;
  25. }
  26. int main()
  27. {
  28.     int n , x , cnt = 0;
  29.     fin >> n;
  30.     for(int i = 1 ; i <= n ; ++i)
  31.     {
  32.         fin >> x;
  33.         if(x != 1 && prim(nrdiv(x))) cnt++;
  34.     }
  35.     fout << cnt;
  36.  
  37.     fin.close();
  38.     fout.close();
  39.  
  40.     return 0;
  41. }
RAW Paste Data