QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#569941#9309. Graphu2x1RE 0ms0kbC++173.5kb2024-09-17 12:36:072024-09-17 12:36:07

Judging History

你现在查看的是最新测评结果

  • [2024-09-17 12:36:07]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-09-17 12:36:07]
  • 提交

answer

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define ll long long
#define all(v) v.begin(),v.end()
#define sz(v) ((ll)v.size())
#define V vector
#define vi V<int>
#define vll V<ll>
#define eb emplace_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define A array
#define pb push_back
#define mset multiset
#define umap __gnu_pbds::gp_hash_table
#define ui unsigned int
#define ull unsigned ll
#define i128 __int128
#define cerr if (test) cerr
#define freopen if (test) freopen
#define whtest if (test)
using namespace std;

const int test = 1;

namespace jhsy {
  constexpr int P = 998244353,N = 1e6,BUC = 999983;
  template<class T,class U,int N,int BUC,ll (*Hash)(ll)>
  struct HashMap {
    struct Node {
      int nxt; T key; U val;
    };
    A<Node,N> a;
    A<int,BUC> head,col;
    int sz{},ver{1};
    void clear() {
     sz = 0; ver++;
    }
    auto end() {return a.end();}
    auto find(const T &key) {
     const int id = Hash(key);
     if (col[id] < ver) {
      return a.end();
     }
     for (int i = head[id]; i != -1; i = a[i].nxt) {
      if (key == a[i].key) {
       return a.begin()+i;
      }
     }
     return a.end();
    }
    auto ins(const T &key,const U &val = {}) {
     const int id = Hash(key);
     if (col[id] < ver) {
      head[id] = -1; col[id] = ver;
     }
     int x = sz++;
     a[x] = {head[id],key,val};
     head[id] = x;
     return a.begin()+x;
    }
    auto& operator[] (const T key) {
     auto it = find(key);
     if (it != end()) {
      return it->val;
     }
     return ins(key)->val;
    }
  };

  vi p;
  void init(const int n = N) {
   A<bool,N+1> isp; isp.fill(1);
   for (int i = 2; i <= n; i++) {
    if (isp[i]) {
     p.eb(i);
    }
    for (auto x:p) {
     if (i*x > n) {
      break;
     }
     isp[i*x] = 0;
     if (!(i%x)) {
      break;
     }
    }
   }
   cerr << p.back() << '\n';
  }
  ll power(ll b,ll k) {
   ll a = 1;
   b = (b%P+P)%P;
   k = (k%(P-1)+(P-1))%(P-1);
   for (; k; b = b*b%P, k >>= 1) {
    if (k&1) {
     a = a*b%P;
    }
   }
   return a;
  }
  void main() {
   ll n;
   cin >> n;
   ll ans = 1;
   auto Hash = [](ll x) {
     return x%BUC;
   };
   HashMap<ll,ll,N,BUC,Hash> mp;
   {
    vll vec;
    for (ll lst = 0,cur; lst < n; lst = cur) {
     ll k = n/(lst+1); cur = n/k;
     vec.eb(cur);
    }
    reverse(all(vec));
    for (auto x:vec) {
     mp[x] = x-1;
    }
    for (int k = 0; k < sz(p); k++) {
     ll t = 1ll*p[k]*p[k];
     if (t > n) {
      break;
     }
     for (auto x:vec) {
      if (t > x) {
       break;
      }
      mp[x] -= mp[x/p[k]]-k;
     }
    }
   }
   auto get_p = [&](ll x) -> ll {
     return mp[x];
   };
   auto get = [&](ll x) {
     ll res = get_p(x)-get_p(x/2);
     if (x/2 < 2 && x >= 2) {
      res--;
     }
     return res;
   };
   auto calc = [&](ll x) -> ll {
     if (x == 1) {
      return 1;
     }
     ll p = get(x)+1,q = x-p;
     return q%P*power(p+q,p-1)%P;
   };
   for (ll lst = 0,cur; lst < n; lst = cur) {
    ll k = n/(lst+1); cur = n/k;
    ans = ans*power(calc(k),cur-lst)%P;
   }
   cout << ans << '\n';
  }
}

int main() {
 freopen("test.in", "r", stdin);
 freopen("test.out", "w", stdout);
 ios::sync_with_stdio(false);
 cin.tie(nullptr);
 cout << fixed << setprecision(20);

 jhsy::init();

 int T = 1;
//  cin >> T;
 while (T--) {
  jhsy::main();
 }

 return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

4

output:


result: