QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#571477 | #9309. Graph | USTC_fish_touching_team | AC ✓ | 296ms | 31296kb | C++14 | 1.7kb | 2024-09-17 23:23:57 | 2024-09-17 23:23:58 |
Judging History
answer
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#define LL long long
#define FOR(i,x,y) for(int i=x;i<y;i++)
using namespace std;
namespace min25{
const int M=2e6+100;
LL B,N;
inline LL pg(LL x){return 1;}
inline LL psg(LL x){return x-1;}
LL pr[M],pc,sg[M];
void get_prime(LL n){
static bool vis[M];pc=0;
FOR(i,2,n+1){
if(!vis[i]){
pr[pc++]=i;
sg[pc]=(sg[pc-1]+pg(i));
}
FOR(j,0,pc){
if(pr[j]*i>n)break;
vis[pr[j]*i]=1;
if(i%pr[j]==0)break;
}
}
}
LL w[M];
LL id1[M],id2[M],g[M];
inline LL id(LL x){
return x<=B?id1[x]:id2[N/x];
}
void solve(LL _N){
N=_N;
B=sqrt(N+5);
get_prime(B);
int sz=0;
for(LL l=1,v,r;l<=N;l=r+1){
v=N/l;r=N/v;
w[sz]=v;g[sz]=psg(v);
if(v<=B)id1[v]=sz;
else id2[r]=sz;
sz++;
}
FOR(k,0,pc){
LL p=pr[k];
FOR(i,0,sz){
LL v=w[i];if(p*p>v)break;
LL t=id(v/p);
g[i]=(g[i]-(g[t]-sg[k])*pg(p));
}
}
}
LL calc(LL l,LL r){
return g[id(r)]-g[id(l-1)];
}
}
const LL mod=998244353;
LL Pow(LL a,LL b){
LL r=1;a%=mod;
while(b){
if(b&1)r=r*a%mod;
b>>=1; a=a*a%mod;
}
return r;
}
LL solve(LL n){
if(n==1)return 0;
return min25::calc(n/2+1,n);
}
LL n;
int main(){
scanf("%lld",&n);
min25::solve(n);
LL res=1;
for(LL l=1,v,r;l<=n;l=r+1){
v=n/l,r=n/v;
if(v<=2)break;
LL g=solve(v)+1;
// printf("v=%lld g=%lld l=%lld\n",v,g,l);
// printf("l=%lld v=%lld b=%lld\n",l,v,b);
LL val=Pow(v,g-1)*((v-g)%mod)%mod;
if(v==g)val=Pow(v,g-2);
res=res*Pow(val,r-l+1)%mod;
}
printf("%lld",(res%mod+mod)%mod);
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 14040kb
input:
4
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 2ms
memory: 11928kb
input:
2
output:
1
result:
ok answer is '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 13976kb
input:
123
output:
671840470
result:
ok answer is '671840470'
Test #4:
score: 0
Accepted
time: 2ms
memory: 14032kb
input:
233
output:
353738465
result:
ok answer is '353738465'
Test #5:
score: 0
Accepted
time: 2ms
memory: 14112kb
input:
5981
output:
970246821
result:
ok answer is '970246821'
Test #6:
score: 0
Accepted
time: 0ms
memory: 14128kb
input:
86422
output:
897815688
result:
ok answer is '897815688'
Test #7:
score: 0
Accepted
time: 2ms
memory: 14044kb
input:
145444
output:
189843901
result:
ok answer is '189843901'
Test #8:
score: 0
Accepted
time: 0ms
memory: 13996kb
input:
901000
output:
819449452
result:
ok answer is '819449452'
Test #9:
score: 0
Accepted
time: 0ms
memory: 14196kb
input:
1000000
output:
113573943
result:
ok answer is '113573943'
Test #10:
score: 0
Accepted
time: 1ms
memory: 14120kb
input:
23333333
output:
949849384
result:
ok answer is '949849384'
Test #11:
score: 0
Accepted
time: 3ms
memory: 14204kb
input:
102850434
output:
604886751
result:
ok answer is '604886751'
Test #12:
score: 0
Accepted
time: 16ms
memory: 14664kb
input:
998244353
output:
0
result:
ok answer is '0'
Test #13:
score: 0
Accepted
time: 12ms
memory: 14704kb
input:
1000000007
output:
318420284
result:
ok answer is '318420284'
Test #14:
score: 0
Accepted
time: 21ms
memory: 18816kb
input:
2147483547
output:
688759898
result:
ok answer is '688759898'
Test #15:
score: 0
Accepted
time: 34ms
memory: 17328kb
input:
5120103302
output:
116870489
result:
ok answer is '116870489'
Test #16:
score: 0
Accepted
time: 101ms
memory: 22416kb
input:
19834593299
output:
523663743
result:
ok answer is '523663743'
Test #17:
score: 0
Accepted
time: 189ms
memory: 27004kb
input:
52500109238
output:
195086665
result:
ok answer is '195086665'
Test #18:
score: 0
Accepted
time: 264ms
memory: 29720kb
input:
84848352911
output:
107959260
result:
ok answer is '107959260'
Test #19:
score: 0
Accepted
time: 294ms
memory: 31296kb
input:
99824435322
output:
0
result:
ok answer is '0'
Test #20:
score: 0
Accepted
time: 294ms
memory: 29912kb
input:
99999999354
output:
316301711
result:
ok answer is '316301711'
Test #21:
score: 0
Accepted
time: 296ms
memory: 29996kb
input:
100000000000
output:
396843576
result:
ok answer is '396843576'
Extra Test:
score: 0
Extra Test Passed