QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#576087 | #9309. Graph | LOOP0 | WA | 17ms | 53148kb | C++14 | 1.7kb | 2024-09-19 18:19:58 | 2024-09-19 18:19:58 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1000000;
int p1,vt,z[N+5],pr[N+5];
long long x,v[N+5],f[2][N+5],s[N+5],g[N+5];
const signed mod=998244353;
void dd(){
p1=0;
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(long long n){
x=sqrt(n)+1;
memset(v,0,sizeof v);
memset(f,0,sizeof f);
memset(s,0,sizeof s);
memset(g,0,sizeof g);
dd();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];
}
}
}
long long S(long long p,int q,long long n){
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;
}
long long calc(long long n){
init(n);
return S(n,0,n);
}
long long fpow(long long a,int b){
long long ans=1;
while(b){
if(b&1) ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
signed main()
{
long long n;
scanf("%lld",&n);
if(n==1){
printf("1\n");
}
else{
long long cnt=calc(n)-calc(n/2)+1;
//printf()
long long res=n-cnt;
//printf("cnt=%lld\n",cnt);
if(res==0){
printf("%lld\n",fpow(n%mod,cnt-2));
}
else{
printf("%lld\n",fpow(n%mod,cnt-1)*(res%mod)%mod);
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 15ms
memory: 51772kb
input:
4
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 13ms
memory: 51472kb
input:
2
output:
1
result:
ok answer is '1'
Test #3:
score: -100
Wrong Answer
time: 17ms
memory: 53148kb
input:
123
output:
454824460
result:
wrong answer expected '671840470', found '454824460'