QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#578164 | #9309. Graph | niolle | TL | 110ms | 32024kb | C++14 | 2.0kb | 2024-09-20 17:06:12 | 2024-09-20 17:06:12 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dwn(i,a,b) for(int i=a;i>=b;i--)
#define lowbit(x) (x&(-x))
#define MAXN 1002501
#define N 1000000
#define int long long
#define mp(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch>'9' || ch<'0'){if(ch=='-') f=-1; ch=getchar();}
while('0'<=ch && ch<='9') x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
return x*f;
}
const int mod = 998244353;
int pri[MAXN],cnt,bk[MAXN],id1[MAXN],id2[MAXN],n;
int w[MAXN],tot,g[MAXN],sp[MAXN],ans;
void Add(int &x,int y){
x += y;
if(x >= mod) x -= mod;
if(x < 0) x += mod;
}
int ksm(int x,int y){
x %= mod;
int res = 1;
while(y){
if(y&1) res = res * x % mod;
x = x * x % mod;
y>>=1;
}
return res;
}
void shai(){
rep(i,2,N){
if(!bk[i]){
bk[i] = i;
pri[++cnt] = i;
sp[cnt] = (sp[cnt-1] + 1) % mod;
}
rep(j,1,cnt){
if(i * pri[j] > N || bk[i] < pri[j]) break;
bk[i*pri[j]] = pri[j];
}
}
}
void pre(){
n = read();
for(int l = 1,r; l <= n; l = r + 1){
r = n/(n/l);
ll k = n/l;
w[++tot] = k;
if(k <= N) id1[k] = tot;
else id2[n/k] = tot;
g[tot] = (k-1)%mod;
}
int l,k;
rep(i,1,cnt){
rep(j,1,tot){
if(w[j] < pri[i] * pri[i]) break;
l = w[j] / pri[i];
if(l <= N) k = id1[l];
else k = id2[n/l];
Add(g[j],-(g[k]-sp[i-1])%mod);
}
}
}
void wk(){
int k,j,k2,i,p;
ll res;
ans = 1;
for(int l = 1,r; l <= n; l = r + 1){
r = n / (n/l);
k = n / l;
if(k <= N) j = id1[k];
else j = id2[n/k];
k2 = k / 2;
if(k2 <= N) i = id1[k2];
else i = id2[n/k2];
p = g[j] - g[i] + 2;
if(p > k) p = k;
if(p == 1) res = 1;
else if(p == k) res = ksm(k,k-2);
else if(p == 2) res = k-1;
else res = ksm(k,p-2) * ((k-p+1)%mod) % mod;
res %= mod;
// if(res < 0) cout<<"QAQ";
ans = ans * ksm(res,r-l+1) % mod;
}
}
signed main(){
shai();
pre();
wk();
cout << ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 6ms
memory: 18724kb
input:
4
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 0ms
memory: 21884kb
input:
2
output:
1
result:
ok answer is '1'
Test #3:
score: 0
Accepted
time: 10ms
memory: 18856kb
input:
123
output:
671840470
result:
ok answer is '671840470'
Test #4:
score: 0
Accepted
time: 11ms
memory: 22028kb
input:
233
output:
353738465
result:
ok answer is '353738465'
Test #5:
score: 0
Accepted
time: 3ms
memory: 18784kb
input:
5981
output:
970246821
result:
ok answer is '970246821'
Test #6:
score: 0
Accepted
time: 5ms
memory: 20932kb
input:
86422
output:
897815688
result:
ok answer is '897815688'
Test #7:
score: 0
Accepted
time: 4ms
memory: 21776kb
input:
145444
output:
189843901
result:
ok answer is '189843901'
Test #8:
score: 0
Accepted
time: 7ms
memory: 24884kb
input:
901000
output:
819449452
result:
ok answer is '819449452'
Test #9:
score: 0
Accepted
time: 8ms
memory: 24456kb
input:
1000000
output:
113573943
result:
ok answer is '113573943'
Test #10:
score: 0
Accepted
time: 8ms
memory: 25104kb
input:
23333333
output:
949849384
result:
ok answer is '949849384'
Test #11:
score: 0
Accepted
time: 3ms
memory: 25156kb
input:
102850434
output:
604886751
result:
ok answer is '604886751'
Test #12:
score: 0
Accepted
time: 21ms
memory: 28616kb
input:
998244353
output:
0
result:
ok answer is '0'
Test #13:
score: 0
Accepted
time: 26ms
memory: 25964kb
input:
1000000007
output:
318420284
result:
ok answer is '318420284'
Test #14:
score: 0
Accepted
time: 29ms
memory: 26956kb
input:
2147483547
output:
688759898
result:
ok answer is '688759898'
Test #15:
score: 0
Accepted
time: 47ms
memory: 27028kb
input:
5120103302
output:
116870489
result:
ok answer is '116870489'
Test #16:
score: 0
Accepted
time: 110ms
memory: 32024kb
input:
19834593299
output:
523663743
result:
ok answer is '523663743'
Test #17:
score: -100
Time Limit Exceeded
input:
52500109238