UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#215346#2478. 数!!erican100556ms3940kbC++112.8kb2024-11-28 20:10:402024-11-28 23:11:35

answer

/*  Erica N  */
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define endl '\n'
#define mp make_pair
#define int long long
#define ull unsigned long long
#define pii pair<int, int>
#define ps second
#define pf first
#define itn int
#define rd read()
int read(){
    int xx = 0, ff = 1;char ch = getchar();
    while (ch < '0' || ch > '9') {if (ch == '-')ff = -1; ch = getchar();}
    while (ch >= '0' && ch <= '9')xx = xx * 10 + (ch - '0'), ch = getchar();
    return xx * ff;
}
// void write(int out) {
// 	if (out < 0)
// 		putchar('-'), out = -out;
// 	if (out > 9)
// 		write(out / 10);
// 	putchar(out % 10 + '0');
// }
#define cdbg(x...) do { cerr << #x << " -> "; err(x); } while (0)
void err() { cerr << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cerr << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }


const int N = 3e5 + 5;
const int INF = 1e18;
const int M = 1e7;
const int MOD = 1e9 + 7;



int p[N],isp[N];

map<int,bool> imp;
itn a[N];
int ans[N];
int tot;
int g[N];


void init(){
    for(int i=2;i<N;i++){
        if(!isp[i]){
            isp[i]=i;
            p[++tot]=i;
        }

        for(int j=1;j<=tot;j++){
            if(p[j]*i>=N)break;
            isp[i*p[j]]=p[j];
            if(i%p[j]==0)break;
        }
    }
}

int getv(int a){
    int t=a;
    int res=0;
    for(int i=1;p[i]*p[i]<=t;i++){
        if(a%p[i])continue;
        int op=imp[p[i]]?-1:1;
        while(a%p[i]==0){
            a/=p[i];
            res-=op;
        }
    }
    if(a>1){
        if(imp[a])res++;
        else res--;
    }

    return res;
}

signed main() {
    // freopen(".in","r",stdin);
    // freopen(".out","w",stdout);


    int n=rd,m=rd;
    init();
    for(int i=1;i<=n;i++){
        // cdbg(p[i]);
        a[i]=rd;
    }

    for(int j=1;j<=m;j++){
        imp[rd]=1;
    }

    for(int i=1;i<=n;i++){
        g[i]=__gcd(g[i-1],a[i]);
    }


    for(int i=1;i<=n;i++){
        ans[i]=-getv(a[i]);

        // cdbg(ans[i]);
        // int t=a[i];

        // for(int j=2;p[j]*p[j]<=a[i];j++){
        //     if(t%p[j])continue;
        //     int op=imp[p[j]]?-1:1;
        //     while(t%p[j]==0){
        //         t/=p[j];
        //         ans[i]+=op;
        //     }
        // }
        // if(t>1){
        //     if(imp[t])ans[i]--;
        //     else ans[i]++;
        // }
    }


    for(int i=n;i;i--){
        int v=getv(g[i]);
        if(v>0){
            for(int j=1;j<=i;j++)g[j]/=g[i],ans[j]+=v;
        }
    }


    int res=0;
    for(int i=1;i<=n;i++){
        res+=ans[i];
    }

    cout<<res<<endl;



    


}

详细

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

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 5ms
memory: 3756kb

input:

1 1
2
2

output:

0

result:

ok single line: '0'

Test #2:

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

input:

1 1
2
3

output:

1

result:

ok single line: '1'

Test #3:

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

input:

3 1
2 4 8
2

output:

-3

result:

ok single line: '-3'

Subtask #2:

score: 20
Accepted

Test #4:

score: 20
Accepted
time: 5ms
memory: 3756kb

input:

2 1
18 2
2

output:

2

result:

ok single line: '2'

Test #5:

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

input:

4 2
30 30 5 5
2 3

output:

2

result:

ok single line: '2'

Test #6:

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

input:

15 7
60 30 100 75 20 33 12 35 23 62 32 90 24 52 23
3 5 11 13 19 23 101

output:

7

result:

ok single line: '7'

Subtask #3:

score: 10
Accepted

Test #7:

score: 10
Accepted
time: 5ms
memory: 3760kb

input:

35 1
20736 2304 73728 1296 1728 216 864 3456 110592 10368 147456 288 9216 2592 331776 663552 1152 14...

output:

188

result:

ok single line: '188'

Test #8:

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

input:

35 1
147456 288 165888 55296 442368 864 3456 576 41472 663552 13824 10368 72 6912 5184 1296 4608 737...

output:

188

result:

ok single line: '188'

Test #9:

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

input:

32 1
2916 108 216 1458 34992 54 18 648 5832 6 36 324 432 104976 11664 17496 13122 4374 1296 72 972 1...

output:

-47

result:

ok single line: '-47'

Subtask #4:

score: 20
Accepted

Test #10:

score: 20
Accepted
time: 7ms
memory: 3768kb

input:

100 39
55963308 984638924 41032888 833281249 814004061 372491234 516777004 12668415 19664367 8195111...

output:

425

result:

ok single line: '425'

Test #11:

score: 0
Accepted
time: 7ms
memory: 3768kb

input:

100 30
807458350 234646743 73099793 585439031 78447394 762454844 524527133 533941279 54244237 436163...

output:

402

result:

ok single line: '402'

Test #12:

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

input:

100 7
671352881 601723584 131976667 593070892 190314381 806913088 528979675 530619743 75485283 59444...

output:

405

result:

ok single line: '405'

Test #13:

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

input:

100 43
602359651 412275154 667978141 72412956 149022075 515893598 14253520 397019552 645066892 68270...

output:

420

result:

ok single line: '420'

Test #14:

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

input:

100 45
109852216 659556677 672550819 894716811 742232723 423777589 788776847 494296357 243128233 402...

output:

370

result:

ok single line: '370'

Subtask #5:

score: 15
Accepted

Test #15:

score: 15
Accepted
time: 45ms
memory: 3936kb

input:

2000 83
1 847093291 382203707 11795829 732991987 572089539 46752335 27875514 293639495 101157403 597...

output:

8030

result:

ok single line: '8030'

Test #16:

score: 0
Accepted
time: 45ms
memory: 3932kb

input:

2000 65
1 894158865 825317666 620512681 534233920 13520317 493245981 359586805 136928065 583523268 4...

output:

8100

result:

ok single line: '8100'

Test #17:

score: 0
Accepted
time: 44ms
memory: 3936kb

input:

2000 84
1 382857625 80364735 518911717 420320039 326384172 33753645 125206551 417599708 638300721 17...

output:

7946

result:

ok single line: '7946'

Test #18:

score: 0
Accepted
time: 48ms
memory: 3936kb

input:

2000 34
1 618009607 36020973 929512863 125824987 830425694 101380318 674440470 456055029 273376102 1...

output:

8095

result:

ok single line: '8095'

Test #19:

score: 0
Accepted
time: 43ms
memory: 3936kb

input:

2000 69
1 285988632 34012906 859151285 393316072 84860647 39757901 480944703 318138454 794464495 131...

output:

8031

result:

ok single line: '8031'

Subtask #6:

score: 10
Accepted

Test #20:

score: 10
Accepted
time: 8ms
memory: 3884kb

input:

2000 90
732495 785432 714893 954891 479586 221979 551506 327947 344542 493501 383766 41829 639983 10...

output:

7358

result:

ok single line: '7358'

Test #21:

score: 0
Accepted
time: 8ms
memory: 3880kb

input:

2000 17
53165 611946 416649 674924 172614 557897 245494 53564 48910 638992 441423 321506 285285 2857...

output:

7210

result:

ok single line: '7210'

Test #22:

score: 0
Accepted
time: 8ms
memory: 3884kb

input:

2000 40
577062 708537 60432 666426 937013 183103 673850 188517 916161 665420 573506 146759 273437 14...

output:

7321

result:

ok single line: '7321'

Test #23:

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

input:

2000 27
518985 638050 453258 823576 267106 15755 398108 410949 757682 738086 254637 503914 918541 20...

output:

7327

result:

ok single line: '7327'

Test #24:

score: 0
Accepted
time: 8ms
memory: 3880kb

input:

2000 16
506895 817207 936837 663303 800812 839411 529740 723370 319909 773205 160646 683465 974107 1...

output:

7335

result:

ok single line: '7335'

Subtask #7:

score: 5
Accepted

Test #25:

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

input:

2000 65
79610144 529207300 674986588 907408557 40519993 721716208 342931725 358601080 21591396 87849...

output:

8126

result:

ok single line: '8126'

Test #26:

score: 0
Accepted
time: 48ms
memory: 3936kb

input:

2000 23
112162568 36490648 503891096 890018181 703697300 57604626 227080400 791018720 155329058 7012...

output:

8077

result:

ok single line: '8077'

Test #27:

score: 0
Accepted
time: 46ms
memory: 3936kb

input:

2000 28
530531614 938263045 57748244 47730064 482466018 61305825 388695902 69153315 53561789 3687236...

output:

8264

result:

ok single line: '8264'

Test #28:

score: 0
Accepted
time: 51ms
memory: 3940kb

input:

2000 58
152149073 547665030 925374630 234630834 984704487 562457138 209076336 119568746 176642539 99...

output:

8016

result:

ok single line: '8016'

Test #29:

score: 0
Accepted
time: 48ms
memory: 3932kb

input:

2000 44
371031216 27082163 139024242 570706323 891353786 255487429 826533270 772591212 461650663 544...

output:

8043

result:

ok single line: '8043'

Extra Test:

score: 0
Extra Test Passed