QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#578981 | #9309. Graph | SSL_TJH | AC ✓ | 290ms | 30504kb | C++14 | 1.7kb | 2024-09-21 00:21:25 | 2024-09-21 00:21:25 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define MOD 998244353
#define ll long long
using namespace std;
const ll MAXN=1e11;
const int N=1e6;
// SQRN is exactly floor(sqrt(n)), PNUM is the number of primes not greater than SQRN
int POW(int x, int y) {
int re = 1;
while (y) {
if (y & 1) re = 1ll * re * x % MOD;
x = 1ll * x * x % MOD; y >>= 1;
}
return re;
}
int p1,vt,z[N+5],pr[N+5],f[2][N+5],x,s[N+5],g[N+5];
long long n,v[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;
vt = 0;
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];
}
}
}
int quest(ll p) {
int td=(p<=x?f[0][p]:f[1][n/p]);
return g[td];
}
int main() {
dd();
ll nn;
scanf("%lld", &nn);
n = nn; init();
if (nn == 2) {
printf("1"); return 0;
}
if (nn == 3) {
printf("3"); return 0;
}
int re = 1;
for (ll L = 1, R; L <= nn; L = R + 1) {
R = nn / (nn / L);
ll k = nn / L;
if (k < 3) continue;
if (k == 3) {
re = 1ll * re * POW(3, (R - L + 1) % (MOD - 1)) % MOD;
continue;
}
int awa = quest(k) - quest(k / 2);
re = 1ll * re * POW((k - awa - 1) % MOD * POW(k % MOD, awa) % MOD, (R - L + 1) % (MOD - 1)) % MOD;//k-awa-1: sz of the block where 2 in
}
printf("%d", re);
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 17960kb
input:
4
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 6ms
memory: 15800kb
input:
2
output:
1
result:
ok answer is '1'
Test #3:
score: 0
Accepted
time: 6ms
memory: 18000kb
input:
123
output:
671840470
result:
ok answer is '671840470'
Test #4:
score: 0
Accepted
time: 3ms
memory: 20104kb
input:
233
output:
353738465
result:
ok answer is '353738465'
Test #5:
score: 0
Accepted
time: 3ms
memory: 17964kb
input:
5981
output:
970246821
result:
ok answer is '970246821'
Test #6:
score: 0
Accepted
time: 3ms
memory: 18096kb
input:
86422
output:
897815688
result:
ok answer is '897815688'
Test #7:
score: 0
Accepted
time: 3ms
memory: 18060kb
input:
145444
output:
189843901
result:
ok answer is '189843901'
Test #8:
score: 0
Accepted
time: 3ms
memory: 19904kb
input:
901000
output:
819449452
result:
ok answer is '819449452'
Test #9:
score: 0
Accepted
time: 3ms
memory: 18068kb
input:
1000000
output:
113573943
result:
ok answer is '113573943'
Test #10:
score: 0
Accepted
time: 5ms
memory: 20180kb
input:
23333333
output:
949849384
result:
ok answer is '949849384'
Test #11:
score: 0
Accepted
time: 6ms
memory: 18272kb
input:
102850434
output:
604886751
result:
ok answer is '604886751'
Test #12:
score: 0
Accepted
time: 20ms
memory: 18384kb
input:
998244353
output:
0
result:
ok answer is '0'
Test #13:
score: 0
Accepted
time: 22ms
memory: 22484kb
input:
1000000007
output:
318420284
result:
ok answer is '318420284'
Test #14:
score: 0
Accepted
time: 22ms
memory: 20668kb
input:
2147483547
output:
688759898
result:
ok answer is '688759898'
Test #15:
score: 0
Accepted
time: 43ms
memory: 20580kb
input:
5120103302
output:
116870489
result:
ok answer is '116870489'
Test #16:
score: 0
Accepted
time: 101ms
memory: 27752kb
input:
19834593299
output:
523663743
result:
ok answer is '523663743'
Test #17:
score: 0
Accepted
time: 187ms
memory: 29624kb
input:
52500109238
output:
195086665
result:
ok answer is '195086665'
Test #18:
score: 0
Accepted
time: 262ms
memory: 30504kb
input:
84848352911
output:
107959260
result:
ok answer is '107959260'
Test #19:
score: 0
Accepted
time: 290ms
memory: 30120kb
input:
99824435322
output:
0
result:
ok answer is '0'
Test #20:
score: 0
Accepted
time: 288ms
memory: 27240kb
input:
99999999354
output:
316301711
result:
ok answer is '316301711'
Test #21:
score: 0
Accepted
time: 288ms
memory: 29436kb
input:
100000000000
output:
396843576
result:
ok answer is '396843576'
Extra Test:
score: 0
Extra Test Passed