QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#695690#9309. GraphWuyanruWA 286ms13892kbC++142.4kb2024-10-31 20:36:122024-10-31 20:36:16

Judging History

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

  • [2024-10-31 20:36:16]
  • 评测
  • 测评结果:WA
  • 用时:286ms
  • 内存:13892kb
  • [2024-10-31 20:36:12]
  • 提交

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

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 7884kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

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

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

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

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

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

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

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

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

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

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

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

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

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

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

score: 0
Accepted
time: 2ms
memory: 8028kb

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

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

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 16ms
memory: 8064kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

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

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 31ms
memory: 10068kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

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

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: 0
Accepted
time: 146ms
memory: 13456kb

input:

19834593299

output:

523663743

result:

ok answer is '523663743'

Test #17:

score: -100
Wrong Answer
time: 286ms
memory: 13892kb

input:

52500109238

output:

78396536

result:

wrong answer expected '195086665', found '78396536'