Advertisement
tien_noob

Divisor Analysis - CSES

Sep 2nd, 2021
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. //Make CSP great again
  2. #include <bits/stdc++.h>
  3. #define TASK "TESTCODE"
  4. using namespace std;
  5. const int N = 1e6, mod = 1e9 + 7;
  6. long long cnt[N + 1];
  7. int n;
  8. int Pow(int a, long long b)
  9. {
  10.     if (b == 0)
  11.     {
  12.         return 1;
  13.     }
  14.     int t = Pow(a, b/2);
  15.     if (b % 2 == 0)
  16.     {
  17.         return (1LL * t * t) % mod;
  18.     }
  19.     else
  20.     {
  21.         return ((1LL * t * t) % mod * a) % mod;
  22.     }
  23. }
  24. int Count(int i)
  25. {
  26.     return (1LL * (Pow(i, cnt[i] + 1) - 1) * Pow(i - 1, mod - 2)) % mod;
  27. }
  28. void read()
  29. {
  30.     cin >> n;
  31.     for (int i = 1; i <= n; ++ i)
  32.     {
  33.         int x, k;
  34.         cin >> x >> k;
  35.         cnt[x] += k;
  36.     }
  37. }
  38. void solve()
  39. {
  40.     int res1 = 1, res2 = 1, res3 = 1, divcnt = 1;
  41.     for (int i = 2; i <= N; ++ i)
  42.     {
  43.         res1 = (1LL * res1 * (cnt[i] + 1)) % mod;
  44.         res2 = (1LL * res2 * Count(i)) % mod;
  45.         res3 = (1LL * Pow(res3, cnt[i] + 1) * Pow(Pow(i, cnt[i] * (cnt[i] + 1)/2), divcnt) ) % mod;
  46.         divcnt = (1LL * divcnt * (cnt[i] + 1)) % (mod - 1);
  47.     }
  48.     cout << res1 << ' ' << res2 << ' ' << res3;
  49. }
  50. int main()
  51. {
  52.     ios_base::sync_with_stdio(false);
  53.     cin.tie(nullptr);
  54.     if (fopen(TASK".INP", "r"))
  55.     {
  56.         freopen(TASK".INP", "r", stdin);
  57.         //freopen(TASK".OUT", "w", stdout);
  58.     }
  59.     int t = 1;
  60.     bool typetest = false;
  61.     if (typetest)
  62.     {
  63.         cin >> t;
  64.     }
  65.     for (int __ = 1; __ <= t; ++ __)
  66.     {
  67.         //cout << "Case " << __ <<": ";
  68.         read();
  69.         solve();
  70.     }
  71. }
  72. ;
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement