QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#566517 | #9309. Graph | 2016gdgzoi471 | TL | 25ms | 42136kb | C++14 | 2.4kb | 2024-09-16 00:20:12 | 2024-09-16 00:20:14 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> vis,prime,g;
vector<vector<int>> f;
ll sqr(ll x){
return x*x;
}
int getsqrt(ll n){
ll t=sqrt(n);
while(sqr(t+1)<=n) t++;
return t;
}
int getcbrt(ll n){
ll t=cbrt(n);
while((t+1)*(t+1)*(t+1)<=n) t++;
return t;
}
void sieve(int n){
vis.assign(n+1,0);
prime.clear();
for(int i=2;i<=n;i++){
if(!vis[i]){
prime.push_back(i);
vis[i]=i;
}
for(int j=0;j<(int)(prime.size());j++){
if(prime[j]>vis[i]||prime[j]>n/i){
break;
}
vis[i*prime[j]]=prime[j];
}
}
}
ll PI(ll n);
ll F(ll n,int m){
if(!m) return n;
if(prime[m]>n) return 0;
if(m<(int)(f.size())&&m<(int)(f[m].size())) return f[m][n];
if(sqr(prime[m])>n) return PI(n)-m+1;
return F(n,m-1)-F(n/prime[m-1],m-1);
}
ll PI(ll n){
if(n<=prime.back()) return g[n];
int i=PI(getcbrt(n-1)+1);
ll tmp=F(n,i)+i-1;
while(1){
ll t=prime[i];
if(t*t>n){
break;
}
tmp-=PI(n/t)-i;
i++;
}
return tmp;
}
void init(ll n){
sieve(getsqrt(n+1)*2);
g.assign(prime.back()+1,0);
int i,j;
for(i=j=0;i<=prime.back();g[i++]=j){
if(i==prime[j]) j++;
}
int A=131072,B=min((int)prime.size(),64);
f.assign(B,vector<int>(A));
for(j=0;j<B;j++)
for(i=0;i<A;i++)
if(j==0){
f[j][i]=i;
}else{
f[j][i]=f[j-1][i]-f[j-1][i/prime[j-1]];
}
}
ll n;
ll F(ll x){
return PI(n/x)-PI(n/x/2)+1;
}
const int mod=998244353;
int fastpow(int a,ll x){
int res=1;
while(x){
if(x&1){
res=1LL*res*a%mod;
}
x>>=1;
a=1LL*a*a%mod;
}
return res;
}
int main(){
scanf("%lld",&n);
init(100000000000LL);
// n=4;
if(n<=2){
puts("1");
return 0;
}
int ans=1;
for(ll i=1,j,nxt;i<=n;i=nxt+1){
j=n/i,nxt=n/j;
ll vf=F(i);
// printf("%lld %lld\n",i,vf);
if(vf==j){
if(j>1){
ans=1LL*ans*fastpow(fastpow(j,j-2),nxt-i+1)%mod;
}
}else{
ans=1LL*ans*fastpow(1LL*fastpow(j,vf-1)*(j-vf)%mod,nxt-i+1)%mod;
}
// printf("%lld\n",ans);
}
printf("%d\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 11ms
memory: 42136kb
input:
4
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 21ms
memory: 41892kb
input:
2
output:
1
result:
ok answer is '1'
Test #3:
score: 0
Accepted
time: 15ms
memory: 42080kb
input:
123
output:
671840470
result:
ok answer is '671840470'
Test #4:
score: 0
Accepted
time: 25ms
memory: 41908kb
input:
233
output:
353738465
result:
ok answer is '353738465'
Test #5:
score: 0
Accepted
time: 15ms
memory: 42124kb
input:
5981
output:
970246821
result:
ok answer is '970246821'
Test #6:
score: 0
Accepted
time: 23ms
memory: 42052kb
input:
86422
output:
897815688
result:
ok answer is '897815688'
Test #7:
score: 0
Accepted
time: 22ms
memory: 41948kb
input:
145444
output:
189843901
result:
ok answer is '189843901'
Test #8:
score: -100
Time Limit Exceeded
input:
901000