QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#858772#2074. LCM SumlgvcAC ✓5658ms353852kbC++234.2kb2025-01-16 22:20:342025-01-16 22:20:41

Judging History

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

  • [2025-01-16 22:20:41]
  • 评测
  • 测评结果:AC
  • 用时:5658ms
  • 内存:353852kb
  • [2025-01-16 22:20:34]
  • 提交

answer

#include <bits/stdc++.h>
#define MOD 1000000007
inline int pw(int a,int b) {
    int as=1;
    while(b) {
        if(b&1) as=1ll*as*a%MOD;
        a=1ll*a*a%MOD;
        b>>=1;
    }
    return as;
}
inline int ni(int a) {
    return pw(a,MOD-2);
}
#define LL long long
LL N;int cf,K,su[34],k,ans,v[34],fa[34][34],C[34][34],f1[34],cc[34],ss[34][34],fq[34],
vi[34],vc[109],xx[34],q,iq[34];LL suu[34];
inline int fd(int x,int y) {
    int aq=0,zz=1;
    for(int i=0;i<=y+1;i++) {
        aq=(aq+1ll*zz*ss[y][i])%MOD;
        zz=1ll*x*zz%MOD;
    }
    return aq;
}
struct n2_t{
    int x,y,ss,v;
} tq[22394889];
struct n_t{
    int x,y,v;
};
std::vector<n_t> tx[33];
inline bool cmp(n2_t x,n2_t y) {
    return (x.x==y.x)?(x.ss<y.ss):(x.x<y.x);
}
void dfs(int n,LL x,LL y,int tp) {
    if(y>N) return;
    if(n==k+1) {
        tq[++cf]=(n2_t){x%MOD,y%MOD,((N-y)/x)%MOD,tp};
        return;
    }
    for(int i=0;i<tx[n].size();i++) {
        LL tt=y;
        while(tt%tx[n][i].x!=tx[n][i].y) tt+=x;
        dfs(n+1,x*tx[n][i].x,tt,1ll*tp*tx[n][i].v%MOD);
    }
}
void sv(int id,int a,int b) {
    //printf("%d %d %d\n",id,a,b);
    std::unordered_map<int,int> qq;
    int num=0,as=0;
    for(int i=b;i<q;i+=a) {
        qq[fa[id][i]]++;
        if(qq[fa[id][i]]>num) as=fa[id][i],num++;
    }
    for(int i=b;i<q;i+=a) {
        fa[id][i]=(fa[id][i]-as+MOD)%MOD;
    }
    if(as) tx[id].push_back((n_t){a,b,as});
    if(a==q) return;
    for(int i=0;i<su[id];i++) sv(id,a*su[id],b+i*a);
}
signed main(void) {
    scanf("%lld %d",&N,&K);
    //mod x = y : chu ???
    // ?????? 
    for(int i=0;i<=K+1;i++) {
        C[i][0]=1;
        for(int j=1;j<=i;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%MOD;
    }
    for(int i=2;i<=K;i++) {
        if(!v[i]) {
            su[++k]=i;
        }
        for(int j=i*2;j<=K;j+=i) v[j]=1;
    }
    for(int i=0;i<=K+1;i++) {
        //i+1 ci duo xiang shi
        int as=0;
        for(int j=0;j<=i+1;j++) {
            as=(as+pw(j,i))%MOD;
            fq[j]=as;
        }
        for(int j=0;j<=i+1;j++) {
            cc[0]=1;
            int az=fq[j],cf=0;
            for(int k=0;k<=i+1;k++) {
                if(j==k) continue;
                for(int l=cf+1;l>=1;l--) {
                    cc[l]=(cc[l-1]+1ll*cc[l]*(MOD-k))%MOD;
                }
                cf++;
                cc[0]=1ll*cc[0]*(MOD-k)%MOD;
                az=1ll*az*ni(j-k+MOD)%MOD;
            }
            for(int k=0;k<=cf;k++) {
                ss[i][k]=(ss[i][k]+1ll*cc[k]*az)%MOD;
            }
            memset(cc,0,sizeof(cc));
        }
    }
    for(int i=1;i<=k;i++) {
        q=1;
        while(q*su[i]<=K) {
            q*=su[i];
        }
        for(int j=0;j<q;j++) {
            int aq=0,ma=0;
            for(int k=0;k<=K;k++) {
                int x=k+((j==0)?q:j),ct=0;
                while(x%su[i]==0) {
                    x/=su[i];
                    ct++;
                }
                aq+=ct;
                ma=std::max(ma,ct);
            }
            fa[i][j]=pw(su[i],MOD-1-(aq-ma));
        }
        sv(i,1,0);
    }
    cc[0]=1;
    for(int j=0;j<=K;j++) {
        for(int k=j+1;k>=1;k--) {
            cc[k]=(cc[k-1]+1ll*cc[k]*j)%MOD;
        }
        cc[0]=0;
    }
    dfs(1,1,0,1);
    std::sort(tq+1,tq+cf+1,cmp);
    int la=0;
    for(int i=1;i<=cf;i++) {
        int la=i;
        while(la<cf&&tq[la].x==tq[la+1].x&&tq[la].ss==tq[la+1].ss) {
            la++;
        }
        int xx=tq[i].ss;
        int x=tq[i].x;
        int aq=1;
        for(int j=0;j<=K+1;j++) {
            f1[j]=1ll*aq*fd(xx,j)%MOD;
            aq=1ll*aq*x%MOD;
        }
        memset(iq,0,sizeof(iq));
        for(int j=0;j<=K+1;j++) {
            for(int k=j;k>=0;k--) {
                iq[j-k]=(iq[j-k]+1ll*f1[k]*C[j][k]%MOD*cc[j])%MOD;
            }
        }
        for(int j=i;j<=la;j++) {
            int y=tq[j].y;
            int ac=tq[j].v;
            for(int j=0;j<=K+1;j++) {
                suu[j]+=ac;
                ac=1ll*ac*y%MOD;
            }
        }
        for(int j=0;j<=K+1;j++) {
            ans=(ans+suu[j]%MOD*iq[j])%MOD;
            suu[j]=0;
        }
        i=la;
    }
    printf("%d",ans);
}

详细

Test #1:

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

input:

10 3

output:

18936

result:

ok single line: '18936'

Test #2:

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

input:

10000 6

output:

43482752

result:

ok single line: '43482752'

Test #3:

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

input:

1000000000 15

output:

688102997

result:

ok single line: '688102997'

Test #4:

score: 0
Accepted
time: 5626ms
memory: 353852kb

input:

1000000000000000000 30

output:

524223287

result:

ok single line: '524223287'

Test #5:

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

input:

1000000000000000000 1

output:

41650

result:

ok single line: '41650'

Test #6:

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

input:

1000000000000000000 2

output:

688702180

result:

ok single line: '688702180'

Test #7:

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

input:

1000000000000000000 3

output:

26803356

result:

ok single line: '26803356'

Test #8:

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

input:

1000000000000000000 4

output:

318915933

result:

ok single line: '318915933'

Test #9:

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

input:

1000000000000000000 5

output:

355484656

result:

ok single line: '355484656'

Test #10:

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

input:

1000000000000000000 6

output:

162499027

result:

ok single line: '162499027'

Test #11:

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

input:

1000000000000000000 7

output:

60587090

result:

ok single line: '60587090'

Test #12:

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

input:

1000000000000000000 8

output:

47433228

result:

ok single line: '47433228'

Test #13:

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

input:

1000000000000000000 9

output:

52651033

result:

ok single line: '52651033'

Test #14:

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

input:

1000000000000000000 10

output:

488431192

result:

ok single line: '488431192'

Test #15:

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

input:

1000000000000000000 11

output:

203359516

result:

ok single line: '203359516'

Test #16:

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

input:

1000000000000000000 12

output:

676816954

result:

ok single line: '676816954'

Test #17:

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

input:

1000000000000000000 13

output:

792261385

result:

ok single line: '792261385'

Test #18:

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

input:

1000000000000000000 14

output:

266241285

result:

ok single line: '266241285'

Test #19:

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

input:

1000000000000000000 15

output:

779954568

result:

ok single line: '779954568'

Test #20:

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

input:

1000000000000000000 16

output:

661462563

result:

ok single line: '661462563'

Test #21:

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

input:

1000000000000000000 17

output:

157882037

result:

ok single line: '157882037'

Test #22:

score: 0
Accepted
time: 4ms
memory: 4096kb

input:

1000000000000000000 18

output:

707666921

result:

ok single line: '707666921'

Test #23:

score: 0
Accepted
time: 4ms
memory: 4096kb

input:

1000000000000000000 19

output:

75350354

result:

ok single line: '75350354'

Test #24:

score: 0
Accepted
time: 6ms
memory: 4224kb

input:

1000000000000000000 20

output:

190809078

result:

ok single line: '190809078'

Test #25:

score: 0
Accepted
time: 9ms
memory: 4480kb

input:

1000000000000000000 21

output:

485802406

result:

ok single line: '485802406'

Test #26:

score: 0
Accepted
time: 32ms
memory: 7644kb

input:

1000000000000000000 22

output:

518652177

result:

ok single line: '518652177'

Test #27:

score: 0
Accepted
time: 58ms
memory: 10240kb

input:

1000000000000000000 23

output:

172946983

result:

ok single line: '172946983'

Test #28:

score: 0
Accepted
time: 71ms
memory: 10424kb

input:

1000000000000000000 24

output:

342420888

result:

ok single line: '342420888'

Test #29:

score: 0
Accepted
time: 109ms
memory: 12344kb

input:

1000000000000000000 25

output:

497552775

result:

ok single line: '497552775'

Test #30:

score: 0
Accepted
time: 113ms
memory: 13540kb

input:

1000000000000000000 26

output:

920161969

result:

ok single line: '920161969'

Test #31:

score: 0
Accepted
time: 347ms
memory: 29980kb

input:

1000000000000000000 27

output:

131607220

result:

ok single line: '131607220'

Test #32:

score: 0
Accepted
time: 1210ms
memory: 90192kb

input:

1000000000000000000 28

output:

551838958

result:

ok single line: '551838958'

Test #33:

score: 0
Accepted
time: 3133ms
memory: 203284kb

input:

1000000000000000000 29

output:

851846988

result:

ok single line: '851846988'

Test #34:

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

input:

1000000000000000000 0

output:

1225

result:

ok single line: '1225'

Test #35:

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

input:

265714758284843011 0

output:

708589

result:

ok single line: '708589'

Test #36:

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

input:

266540997167959139 1

output:

881831692

result:

ok single line: '881831692'

Test #37:

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

input:

267367244641009859 2

output:

423211036

result:

ok single line: '423211036'

Test #38:

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

input:

268193483524125987 3

output:

127124157

result:

ok single line: '127124157'

Test #39:

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

input:

269019726702209411 4

output:

39777520

result:

ok single line: '39777520'

Test #40:

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

input:

269845965585325539 5

output:

577495858

result:

ok single line: '577495858'

Test #41:

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

input:

270672213058376259 6

output:

262428469

result:

ok single line: '262428469'

Test #42:

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

input:

271498451941492387 7

output:

878988911

result:

ok single line: '878988911'

Test #43:

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

input:

272324690824608515 8

output:

844720221

result:

ok single line: '844720221'

Test #44:

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

input:

273150934002691939 9

output:

20339607

result:

ok single line: '20339607'

Test #45:

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

input:

996517375802030518 10

output:

436000085

result:

ok single line: '436000085'

Test #46:

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

input:

997343614685146646 11

output:

172229324

result:

ok single line: '172229324'

Test #47:

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

input:

998169857863230070 12

output:

297495611

result:

ok single line: '297495611'

Test #48:

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

input:

998996101041313494 13

output:

516501983

result:

ok single line: '516501983'

Test #49:

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

input:

999822344219396918 14

output:

917263884

result:

ok single line: '917263884'

Test #50:

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

input:

648583102513046 15

output:

962851231

result:

ok single line: '962851231'

Test #51:

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

input:

1474821985629174 16

output:

635473880

result:

ok single line: '635473880'

Test #52:

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

input:

2301069458679894 17

output:

686837493

result:

ok single line: '686837493'

Test #53:

score: 0
Accepted
time: 4ms
memory: 4096kb

input:

3127308341796022 18

output:

746101270

result:

ok single line: '746101270'

Test #54:

score: 0
Accepted
time: 4ms
memory: 4096kb

input:

3953551519879446 19

output:

517293260

result:

ok single line: '517293260'

Test #55:

score: 0
Accepted
time: 4ms
memory: 4224kb

input:

738505179452405440 20

output:

96504747

result:

ok single line: '96504747'

Test #56:

score: 0
Accepted
time: 11ms
memory: 4608kb

input:

739331418335521569 21

output:

151678490

result:

ok single line: '151678490'

Test #57:

score: 0
Accepted
time: 33ms
memory: 7676kb

input:

740157665808572289 22

output:

548846725

result:

ok single line: '548846725'

Test #58:

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

input:

740983904691688417 23

output:

260809011

result:

ok single line: '260809011'

Test #59:

score: 0
Accepted
time: 70ms
memory: 10224kb

input:

741810147869771841 24

output:

62064725

result:

ok single line: '62064725'

Test #60:

score: 0
Accepted
time: 111ms
memory: 12576kb

input:

742636386752887969 25

output:

378996555

result:

ok single line: '378996555'

Test #61:

score: 0
Accepted
time: 114ms
memory: 12244kb

input:

743462629930971393 26

output:

749268774

result:

ok single line: '749268774'

Test #62:

score: 0
Accepted
time: 353ms
memory: 31312kb

input:

744288873109054817 27

output:

343279726

result:

ok single line: '343279726'

Test #63:

score: 0
Accepted
time: 1204ms
memory: 89848kb

input:

745115111992170945 28

output:

275401202

result:

ok single line: '275401202'

Test #64:

score: 0
Accepted
time: 3111ms
memory: 202528kb

input:

745941355170254369 29

output:

482258407

result:

ok single line: '482258407'

Test #65:

score: 0
Accepted
time: 5653ms
memory: 353836kb

input:

257120946248004555 30

output:

871039750

result:

ok single line: '871039750'

Test #66:

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

input:

96 5

output:

821858903

result:

ok single line: '821858903'

Test #67:

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

input:

52 19

output:

457717981

result:

ok single line: '457717981'

Test #68:

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

input:

96 10

output:

169742074

result:

ok single line: '169742074'

Test #69:

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

input:

37 24

output:

999563342

result:

ok single line: '999563342'

Test #70:

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

input:

81 11

output:

38929854

result:

ok single line: '38929854'

Test #71:

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

input:

21 25

output:

664668034

result:

ok single line: '664668034'

Test #72:

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

input:

70 16

output:

725245983

result:

ok single line: '725245983'

Test #73:

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

input:

22 30

output:

167544969

result:

ok single line: '167544969'

Test #74:

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

input:

63 13

output:

743502454

result:

ok single line: '743502454'

Test #75:

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

input:

7 0

output:

28

result:

ok single line: '28'

Test #76:

score: 0
Accepted
time: 5629ms
memory: 353644kb

input:

267367244641009859 30

output:

625470986

result:

ok single line: '625470986'

Test #77:

score: 0
Accepted
time: 5658ms
memory: 353808kb

input:

268193483524125987 30

output:

55213829

result:

ok single line: '55213829'

Test #78:

score: 0
Accepted
time: 5642ms
memory: 353836kb

input:

269019726702209411 30

output:

965929889

result:

ok single line: '965929889'

Test #79:

score: 0
Accepted
time: 5626ms
memory: 353740kb

input:

269845965585325539 30

output:

87993358

result:

ok single line: '87993358'

Test #80:

score: 0
Accepted
time: 5642ms
memory: 353792kb

input:

270672213058376259 30

output:

88337416

result:

ok single line: '88337416'

Test #81:

score: 0
Accepted
time: 5617ms
memory: 353564kb

input:

271498451941492387 30

output:

753017833

result:

ok single line: '753017833'

Test #82:

score: 0
Accepted
time: 5634ms
memory: 353808kb

input:

272324690824608515 30

output:

972883027

result:

ok single line: '972883027'

Test #83:

score: 0
Accepted
time: 5607ms
memory: 353708kb

input:

273150934002691939 30

output:

644302994

result:

ok single line: '644302994'

Test #84:

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

input:

1 0

output:

1

result:

ok single line: '1'

Test #85:

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

input:

1 1

output:

2

result:

ok single line: '2'

Test #86:

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

input:

1 30

output:

775941393

result:

ok single line: '775941393'

Test #87:

score: 0
Accepted
time: 6ms
memory: 3840kb

input:

100 30

output:

329365290

result:

ok single line: '329365290'