Advertisement
vovanhoangtuan

Product Divisors

Jun 27th, 2020
1,508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const long long mod = (long long)(1e9 + 7);
  6.  
  7. int minPrime[10000000+10];
  8. int a[1000000];
  9.  
  10.  
  11.  
  12.  
  13. void Sieve(int n)
  14. {
  15.     for (int i = 2; i* i <= n; i++)
  16.     {
  17.         if (minPrime[i] == 0)
  18.         {
  19.             for (int j = i * i;  j <= n; j+= i)
  20.             {
  21.                 if (minPrime[j] == 0) minPrime[j] = i;
  22.             }
  23.         }
  24.     }
  25.  
  26.     for (int i = 2; i <= n; i++)
  27.     {
  28.         if (minPrime[i] == 0) minPrime[i] = i;
  29.     }
  30.  
  31. }
  32.  
  33.  
  34. vector<pair<int, int>> PhanTich(int n)
  35. {
  36.     vector<pair<int, int>> res;
  37.     int current = 0;
  38.     while (n > 1)
  39.     {
  40.         if (current != minPrime[n]) current = minPrime[n];
  41.         int num = 0;
  42.         while (current == minPrime[n])
  43.         {
  44.             num++;
  45.             n /= minPrime[n];
  46.         }
  47.  
  48.         res.push_back({current, num});
  49.  
  50.     }
  51.     if (n > 1) res.push_back({n, 1});
  52.     return res;
  53. }
  54.  
  55.  
  56.  
  57. int task(int n)
  58. {
  59.     vector<pair<int, int>> input = PhanTich(n);
  60.     int res = 1;
  61.     for (auto it:input)
  62.     {
  63.         res *= it.second + 1;
  64.     }
  65.     return res;
  66. }
  67.  
  68. int main()
  69. {
  70.     int n;
  71.     cin >> n;
  72.     for (int i = 0; i < n; i++)
  73.     {
  74.         cin >> a[i];
  75.     }
  76.     Sieve(10000000);
  77.     int tich = 1;
  78.  
  79.     for (int i = 0; i < n; i++)
  80.     {
  81.         int temp = task(a[i]);
  82.         tich = ((tich % mod) * (temp % mod)) % mod;
  83.     }
  84.  
  85.     cout << tich << endl;
  86.  
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement