fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int mod = 998244353; int t, n, cnt[8][900005], luythua[255][100005], chon[255], ctrc[255]; vector<int> uoc[900005];
  4. void prepare () {
  5. for (int i = 1; i < 900005; i++) for (int j = i; j < 900005; j += i) uoc[j].push_back(i);
  6. luythua[0][0] = 1;
  7. for (int i = 1; i < 255; i++) {
  8. luythua[i][0] = 1;
  9. for (int j = 1; j < 100005; j++) luythua[i][j] = 1LL*luythua[i][j - 1]*i % mod;
  10. }
  11. }
  12. int getCount(int val, int maxx) {
  13. const vector<int> &wish = uoc[val];
  14. int hh = wish.size(), phu = 0;
  15. memset(chon, 0, sizeof (int)*(hh + 1));
  16. memset(ctrc, 0, sizeof (int)*(hh + 1));
  17. for (int low = 1; low <= 7; low++) if (cnt[low][maxx] != 0) {
  18. while (phu < hh && wish[phu] < low) phu++;
  19. if (phu == hh || cnt[low][wish[phu] - 1] > 0) return 0;
  20. for (int i = phu; i < hh - 1; i++) chon[i - phu + 1] += cnt[low][wish[i + 1] - 1] - cnt[low][wish[i] - 1];
  21. ctrc[hh - phu] += cnt[low][maxx] - cnt[low][wish[hh - 1] - 1];
  22. }
  23. long long res = 1, tmp1 = 1, tmp2 = 1;
  24. for (int i = 1; i <= hh; i++) res = res*luythua[i][chon[i]] % mod, tmp1 = tmp1*luythua[i][ctrc[i]] % mod, tmp2 = tmp2*luythua[i - 1][ctrc[i]] % mod;
  25. return 1LL * res * (tmp1 - tmp2 + mod) % mod;
  26. }
  27. signed main() {
  28. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  29. prepare();
  30. cin >> t;
  31. while (t--) {
  32. memset(cnt, 0, sizeof cnt);
  33. cin >> n;
  34. int maxx = 0;
  35. for (int i = 1; i <= n; i++) {
  36. int l, r; cin >> l >> r;
  37. cnt[l][r]++;
  38. maxx = max(maxx, r);
  39. }
  40. for (int l = 1; l <= 7; l++) for (int i = 1; i <= maxx; i++) cnt[l][i] += cnt[l][i - 1];
  41. int res = 0;
  42. for (int val = 1; val <= maxx; val++) res = (res + getCount(val, maxx)) % mod;
  43. cout << res << '\n';
  44. }
  45. }
  46.  
Success #stdin #stdout 0.93s 205440KB
stdin
Standard input is empty
stdout
Standard output is empty