QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#578892 | #9309. Graph | SSL_TJH | TL | 0ms | 6908kb | C++14 | 1.6kb | 2024-09-20 22:26:43 | 2024-09-20 22:26:43 |
Judging History
answer
#include<bits/stdc++.h>
#define MOD 998244353
using namespace std;
typedef long long ll;
const ll MAXN=1e11;
const int N=1e5;
// SQRN is exactly floor(sqrt(n)), PNUM is the number of primes not greater than SQRN
ll POW(ll x, ll y) {
ll re = 1;
while (y) {
if (y & 1) re = re * x % MOD;
x = x * x % MOD; y >>= 1;
}
return re;
}
int p1,vt,z[N+5],pr[N+5];
long long n,x,v[N+5],f[2][N+5],s[N+5],g[N+5];
void dd(){
for(int i=2;i<=N;i++){
if(!z[i]){
pr[++p1]=i;
s[p1]=p1;
}
for(int j=1;j<=p1&&i*pr[j]<=N;j++){
z[i*pr[j]]=1;
if(i%pr[j]==0) break;
}
}
}
void init(){
x=sqrt(n)+1;
dd();
for(long long l=1,r;l<=n;l=r+1){
r=n/(n/l);
v[++vt]=n/l;
if(n/l<=x) f[0][n/l]=vt;
else f[1][l]=vt;
long long t=n/l;
g[vt]=t-1;
}
long long w;
for(int i=1;i<=p1;i++){
w=1ll*pr[i]*pr[i];
long long t;
for(int j=1;j<=vt&&w<=v[j];j++){
t=v[j]/pr[i];
if(t<=x) t=f[0][t];
else t=f[1][n/t];
g[j]-=g[t]-s[i-1];
}
}
}
long long S(long long p,int q){
if(pr[q]>=p) return 0;
long long td=(p<=x?f[0][p]:f[1][n/p]);
long long re=g[td]-s[q];
return re;
}
int quest(ll m) {
n = m;
init();
return S(n,0);
}
int main() {
ll nn;
scanf("%lld", &nn);
if (nn == 2) {
printf("1"); return 0;
}
if (nn == 3) {
printf("3"); return 0;
}
ll re = 1;
for (ll L = 1, R; L <= nn; L = R + 1) {
R = nn / (nn / L);
int k = (nn / L) % MOD;
ll awa = quest(k) - quest(k / 2);
if (!awa) continue;
(re *= awa % MOD * POW(k, awa) % MOD) %= MOD;
}
printf("%lld", re);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 6908kb
input:
4
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
2
output:
1
result:
ok answer is '1'
Test #3:
score: -100
Time Limit Exceeded
input:
123