UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#213792#2157. 数列Wonder_Fun1005452ms44464kbC++1.3kb2024-11-13 19:44:132024-11-13 23:03:07

answer

#include<stdio.h>
#include<iostream>
using namespace std;
#define maxnn 2000100
#define ll long long
ll zhi[maxnn];
ll n,p;
ll phi[maxnn];
ll cnt[maxnn];
ll len=0;
ll is[maxnn];
void init()
{
    phi[1]=1;
    for(ll i=2;i<=2000000;i++)
    {
        if(!phi[i])
            zhi[++len]=i;
        for(int j=1;j<=len&&zhi[j]*i<=2000000;j++)
        {
            phi[zhi[j]*i]=1;
            if(i%zhi[j]==0) break;
        }
    }
}
void iiit(){
  
    for(ll i=2*n;i>=1;i--)
    {
        if(is[i])
    {
        if(zhi[lower_bound(zhi+1,zhi+len+1,i)-zhi]==i) continue;
        for(int j=2;j*j<=i;j++)
        {
            if(i%j==0)
            {
                is[j]+=is[i];
                is[i/j]+=is[i];
                break;
            }
        }
    }
    }
    for(int i=1;i<=len&&zhi[i]<=2*n;i++)
    {
        if(is[zhi[i]]) cnt[zhi[i]]+=is[zhi[i]];
    }
}
ll ksm(ll a,ll b)
{
    ll ans=1;
    while(b)
    {
        if(b&1) ans=ans*a%p;
        a=a*a%p;
        b>>=1;
    }
    return ans;
}
int main(){
    cin>>n>>p;
    for(ll i=n+2;i<=2*n;i++) is[i]=1;
    for(ll i=1;i<=n;i++) is[i]=-1;
    init();
    iiit();
    ll tot=1;
    for(ll i=1;i<=len&&zhi[i]<=2*n;i++)
    {
        if(cnt[zhi[i]]) tot=tot*ksm(zhi[i],cnt[zhi[i]])%p;
    }
    cout<<tot%p;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 5
Accepted
time: 36ms
memory: 18016kb

input:

921 998054347

output:

345389219

result:

ok single line: '345389219'

Test #2:

score: 5
Accepted
time: 41ms
memory: 18016kb

input:

926 998064329

output:

458756691

result:

ok single line: '458756691'

Test #3:

score: 5
Accepted
time: 38ms
memory: 18024kb

input:

1000 998074327

output:

457273797

result:

ok single line: '457273797'

Test #4:

score: 5
Accepted
time: 41ms
memory: 18020kb

input:

952 998084303

output:

329700115

result:

ok single line: '329700115'

Test #5:

score: 5
Accepted
time: 34ms
memory: 18024kb

input:

989 998094347

output:

94788253

result:

ok single line: '94788253'

Test #6:

score: 5
Accepted
time: 40ms
memory: 18016kb

input:

902 998104313

output:

911969455

result:

ok single line: '911969455'

Test #7:

score: 5
Accepted
time: 39ms
memory: 18016kb

input:

914 998114333

output:

827812986

result:

ok single line: '827812986'

Test #8:

score: 5
Accepted
time: 36ms
memory: 18020kb

input:

986 998124313

output:

169699253

result:

ok single line: '169699253'

Test #9:

score: 5
Accepted
time: 39ms
memory: 18020kb

input:

947 998134339

output:

761932751

result:

ok single line: '761932751'

Test #10:

score: 5
Accepted
time: 42ms
memory: 18020kb

input:

934 998144339

output:

42889072

result:

ok single line: '42889072'

Test #11:

score: 5
Accepted
time: 592ms
memory: 44464kb

input:

991572 998154343

output:

277089318

result:

ok single line: '277089318'

Test #12:

score: 5
Accepted
time: 556ms
memory: 42912kb

input:

932800 998164337

output:

945072504

result:

ok single line: '945072504'

Test #13:

score: 5
Accepted
time: 452ms
memory: 42132kb

input:

903603 998174341

output:

29916736

result:

ok single line: '29916736'

Test #14:

score: 5
Accepted
time: 396ms
memory: 43588kb

input:

958646 998184331

output:

802903490

result:

ok single line: '802903490'

Test #15:

score: 5
Accepted
time: 532ms
memory: 44240kb

input:

983016 998194349

output:

802900579

result:

ok single line: '802900579'

Test #16:

score: 5
Accepted
time: 548ms
memory: 42632kb

input:

922347 998204353

output:

228575331

result:

ok single line: '228575331'

Test #17:

score: 5
Accepted
time: 589ms
memory: 44068kb

input:

976053 998214317

output:

982618317

result:

ok single line: '982618317'

Test #18:

score: 5
Accepted
time: 562ms
memory: 43548kb

input:

957300 998224351

output:

514549818

result:

ok single line: '514549818'

Test #19:

score: 5
Accepted
time: 462ms
memory: 42612kb

input:

921760 998234353

output:

470386410

result:

ok single line: '470386410'

Test #20:

score: 5
Accepted
time: 377ms
memory: 42376kb

input:

912948 998244353

output:

129235345

result:

ok single line: '129235345'