QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#695713#9309. GraphWuyanruAC ✓455ms17796kbC++142.4kb2024-10-31 20:38:542024-10-31 20:38:54

Judging History

你现在查看的是最新测评结果

  • [2024-10-31 20:38:54]
  • 评测
  • 测评结果:AC
  • 用时:455ms
  • 内存:17796kb
  • [2024-10-31 20:38:54]
  • 提交

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 g[2][400005];
ll f1[400005];
ll f2[400005];
ll sq,n;
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& gp(ll w)
{
    if(!w) return g[0][0];
    if(w<=sq) return g[0][w];
    return g[1][n/w];
}
inline ll get(ll m)
{
    ll v=gp(m)-gp(m/2)+1;
    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=lread();
    for(;(sq+1)*(sq+1)<=n;sq++);
    // printf("sq=%lld\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]<=sq;j++)
        {
            is[i*pri[j]]=1;
            if(i%pri[j]==0) break;
        }
    }
    
    vc<ll>num;
    for(ll i=1;i<=sq;i++) num.push_back(i);
    for(ll i=sq;i;i--) num.push_back(n/i);
    num.erase(unique(num.begin(),num.end()),num.end());
    for(ll i:num) gp(i)=i-1;
    
    unsigned sw=0;
    // for(ll i:num) printf("%lld ",i);;putchar('\n');
    for(int i=1;i<=pri[0];i++)
    {
        while(sw<num.size()&&(ll)pri[i]*pri[i]>num[sw]) sw++;
        for(unsigned j=num.size()-1;j>=sw;j--) gp(num[j])-=gp(num[j]/pri[i])-(i-1);
    }

    // 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;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7880kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

score: 0
Accepted
time: 1ms
memory: 8116kb

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: 0
Accepted
time: 1ms
memory: 7840kb

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

score: 0
Accepted
time: 1ms
memory: 7844kb

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

score: 0
Accepted
time: 1ms
memory: 7932kb

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

score: 0
Accepted
time: 0ms
memory: 8080kb

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

score: 0
Accepted
time: 0ms
memory: 7880kb

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

score: 0
Accepted
time: 0ms
memory: 7960kb

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

score: 0
Accepted
time: 1ms
memory: 8148kb

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

score: 0
Accepted
time: 3ms
memory: 8060kb

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: 0
Accepted
time: 3ms
memory: 7968kb

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 20ms
memory: 8224kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

score: 0
Accepted
time: 21ms
memory: 7944kb

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 34ms
memory: 7912kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: 0
Accepted
time: 60ms
memory: 8588kb

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: 0
Accepted
time: 149ms
memory: 12308kb

input:

19834593299

output:

523663743

result:

ok answer is '523663743'

Test #17:

score: 0
Accepted
time: 281ms
memory: 13772kb

input:

52500109238

output:

195086665

result:

ok answer is '195086665'

Test #18:

score: 0
Accepted
time: 396ms
memory: 17796kb

input:

84848352911

output:

107959260

result:

ok answer is '107959260'

Test #19:

score: 0
Accepted
time: 455ms
memory: 16508kb

input:

99824435322

output:

0

result:

ok answer is '0'

Test #20:

score: 0
Accepted
time: 447ms
memory: 16892kb

input:

99999999354

output:

316301711

result:

ok answer is '316301711'

Test #21:

score: 0
Accepted
time: 447ms
memory: 15552kb

input:

100000000000

output:

396843576

result:

ok answer is '396843576'

Extra Test:

score: 0
Extra Test Passed