QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#571867 | #9309. Graph | zhouhuanyi | AC ✓ | 302ms | 15716kb | C++23 | 1.4kb | 2024-09-18 09:33:58 | 2024-09-18 09:33:58 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 632454
#define mod 998244353
using namespace std;
long long read()
{
char c=0;
long long sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
void Adder(int &x,int d)
{
x=x+d>=mod?x+d-mod:x+d;
return;
}
int sn,ans=1,tong[N+1],length,leng;
long long n,st[N+1],dp[N+1];
bool nprime[N+1];
int get(long long x)
{
return x<=sn?x:leng-n/x+1;
}
int fast_pow(int a,long long b)
{
int res=1,mul=a;
while (b)
{
if (b&1) res=1ll*res*mul%mod;
mul=1ll*mul*mul%mod,b>>=1;
}
return res;
}
int solve(long long x)
{
if (x==1) return 1;
else if (x==2) return 1;
else if (x==3) return 3;
else
{
long long d=dp[get(x)]-dp[get(x>>1)];
return 1ll*((x-1-d)%mod)*fast_pow(x%mod,d)%mod;
}
}
int main()
{
long long d;
n=read();
while (1ll*(sn+1)*(sn+1)<=n) ++sn;
for (int i=2;i<=sn;++i)
if (!nprime[i])
{
tong[++length]=i;
for (int j=(i<<1);j<=sn;j+=i) nprime[j]=1;
}
for (long long i=1,lst;i<=n;i=lst+1) lst=n/(n/i),st[++leng]=n/i;
reverse(st+1,st+leng+1);
for (int i=1;i<=leng;++i) dp[i]=st[i]-1;
for (int i=1;i<=length;++i)
for (int j=leng;j>=1&&st[j]>=1ll*tong[i]*tong[i];--j)
dp[j]-=(dp[get(st[j]/tong[i])]-i+1);
for (int i=1;i<=leng;++i) d=n/st[i]-n/(st[i]+1),ans=1ll*ans*fast_pow(solve(st[i]),d)%mod;
printf("%d\n",ans);
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7924kb
input:
4
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 1ms
memory: 7868kb
input:
2
output:
1
result:
ok answer is '1'
Test #3:
score: 0
Accepted
time: 1ms
memory: 7992kb
input:
123
output:
671840470
result:
ok answer is '671840470'
Test #4:
score: 0
Accepted
time: 0ms
memory: 10092kb
input:
233
output:
353738465
result:
ok answer is '353738465'
Test #5:
score: 0
Accepted
time: 0ms
memory: 7904kb
input:
5981
output:
970246821
result:
ok answer is '970246821'
Test #6:
score: 0
Accepted
time: 1ms
memory: 7936kb
input:
86422
output:
897815688
result:
ok answer is '897815688'
Test #7:
score: 0
Accepted
time: 1ms
memory: 7968kb
input:
145444
output:
189843901
result:
ok answer is '189843901'
Test #8:
score: 0
Accepted
time: 0ms
memory: 7964kb
input:
901000
output:
819449452
result:
ok answer is '819449452'
Test #9:
score: 0
Accepted
time: 1ms
memory: 7924kb
input:
1000000
output:
113573943
result:
ok answer is '113573943'
Test #10:
score: 0
Accepted
time: 2ms
memory: 7948kb
input:
23333333
output:
949849384
result:
ok answer is '949849384'
Test #11:
score: 0
Accepted
time: 5ms
memory: 8108kb
input:
102850434
output:
604886751
result:
ok answer is '604886751'
Test #12:
score: 0
Accepted
time: 16ms
memory: 10496kb
input:
998244353
output:
0
result:
ok answer is '0'
Test #13:
score: 0
Accepted
time: 16ms
memory: 10424kb
input:
1000000007
output:
318420284
result:
ok answer is '318420284'
Test #14:
score: 0
Accepted
time: 25ms
memory: 8752kb
input:
2147483547
output:
688759898
result:
ok answer is '688759898'
Test #15:
score: 0
Accepted
time: 39ms
memory: 11284kb
input:
5120103302
output:
116870489
result:
ok answer is '116870489'
Test #16:
score: 0
Accepted
time: 103ms
memory: 14152kb
input:
19834593299
output:
523663743
result:
ok answer is '523663743'
Test #17:
score: 0
Accepted
time: 191ms
memory: 14284kb
input:
52500109238
output:
195086665
result:
ok answer is '195086665'
Test #18:
score: 0
Accepted
time: 275ms
memory: 14628kb
input:
84848352911
output:
107959260
result:
ok answer is '107959260'
Test #19:
score: 0
Accepted
time: 301ms
memory: 15004kb
input:
99824435322
output:
0
result:
ok answer is '0'
Test #20:
score: 0
Accepted
time: 302ms
memory: 15460kb
input:
99999999354
output:
316301711
result:
ok answer is '316301711'
Test #21:
score: 0
Accepted
time: 298ms
memory: 15716kb
input:
100000000000
output:
396843576
result:
ok answer is '396843576'
Extra Test:
score: 0
Extra Test Passed