QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#694144 | #9309. Graph | Wuyanru | RE | 1ms | 6024kb | C++14 | 2.3kb | 2024-10-31 17:20:47 | 2024-10-31 17:20:48 |
Judging History
answer
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f3f3f3f3fll
#define debug(x) cerr<<#x<<"="<<x<<endl
using namespace std;
using ll=long long;
using ld=long double;
using pli=pair<ll,int>;
using pi=pair<int,int>;
template<typename A>
using vc=vector<A>;
inline int read()
{
int s=0,w=1;char ch;
while((ch=getchar())>'9'||ch<'0') if(ch=='-') w=-1;
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
inline ll lread()
{
ll s=0,w=1;char ch;
while((ch=getchar())>'9'||ch<'0') if(ch=='-') w=-1;
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
const int mod=998244353;
int pri[400005];
bool is[400005];
ll f1[400005];
ll f2[400005];
ll sq,n;
inline ll G(ll n,int k)
{
if(!k) return n-1;
if(n==1) return 0;
ll ans=G(n,k-1);
if((ll)pri[k]*pri[k]<=n) ans-=G(n/pri[k],k-1)-(k-1);
return ans;
}
inline ll qow(ll a,ll b)
{
ll ans=1;
while(b)
{
if(b&1) ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
inline ll fp(ll w)
{
if(w<=sq) return f1[w];
return f2[n/w];
}
inline ll get(ll m)
{
ll v=fp(m)-fp(m/2)+1;
v=(v%mod+mod)%mod;
if(m==1) return 1;
if(v==m) return qow(m%mod,m-2);
//共 v 个孤立点和 1 个连通块
// printf("m=%lld v=%lld\n",m,v);
return (m-v)%mod*qow(m%mod,v-1)%mod;
}
int main()
{
n=read();
for(;(sq+1)*(sq+1)<=n;sq++);
for(int i=2;i<=sq;i++)
{
if(!is[i]) pri[++pri[0]]=i;
for(int j=1;j<=pri[0]&&i*pri[j]<=n;j++)
{
is[i*pri[j]]=1;
if(i%pri[j]==0) break;
}
}
// printf("??\n");
int k=0;
for(int i=1;i<=sq;i++)
{
ll lim=i;
while(k<pri[0]&&(ll)pri[k+1]*pri[k+1]<=lim) k++;
f1[i]=G(lim,k)%mod;
}
for(int i=sq;i;i--)
{
ll lim=n/i;
while(k<pri[0]&&(ll)pri[k+1]*pri[k+1]<=lim) k++;
f2[i]=G(lim,k)%mod;
}
// debug(G(11,2));
// debug(G(3,1)-G(2,1));
// for(ll i=1;i<=n;i++) if(i==1||n/i!=n/(i+1)) printf("%lld : %lld\n",n/i,fp(n/i));
ll ans=1;
for(ll l=1,r;l<=n;l=r+1)
{
r=n/(n/l);
// printf("l=%lld r=%lld\n",l,r);
ans=ans*qow(get(n/l),r-l+1)%mod;
// printf("ans=%lld\n",ans);
}
printf("%lld\n",ans);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5884kb
input:
4
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 1ms
memory: 6004kb
input:
2
output:
1
result:
ok answer is '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 5816kb
input:
123
output:
671840470
result:
ok answer is '671840470'
Test #4:
score: 0
Accepted
time: 0ms
memory: 5816kb
input:
233
output:
353738465
result:
ok answer is '353738465'
Test #5:
score: 0
Accepted
time: 1ms
memory: 5820kb
input:
5981
output:
970246821
result:
ok answer is '970246821'
Test #6:
score: 0
Accepted
time: 0ms
memory: 5972kb
input:
86422
output:
897815688
result:
ok answer is '897815688'
Test #7:
score: 0
Accepted
time: 0ms
memory: 6024kb
input:
145444
output:
189843901
result:
ok answer is '189843901'
Test #8:
score: -100
Runtime Error
input:
901000