UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#204410#3602. 最小公倍数lsr1001711ms6760kbC++1.4kb2024-05-19 11:53:012024-05-19 12:31:28

answer

#include <bits/stdc++.h>
using namespace std;

#define QwQ3301AwA return 0
#define ll long long

const int N = 1e6 + 5;
const int mod = 1e9 + 7;
int n;
int p[N], cnt, id[N];
bool vis[N];
int mx[N];

void init(int lim) {
    for (int i = 2; i <= lim; i++) {
        if (!vis[i]) p[++cnt] = i, id[i] = cnt;
        for (int j = 1; j <= cnt && 1ll * i * p[j] <= lim; j++) {
            vis[i * p[j]] = 1;
            if (i % p[j] == 0) break;
        }
    }
}

int ksm(int a, int b) {
    int ans = 1;
    for (; b; b >>= 1, a = 1ll * a * a % mod) {
        if (b & 1) ans = 1ll * ans * a % mod;
    }
    return ans;
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    init(1e6);
    // cout << cnt << '\n';
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int w;
        cin >> w;
        for (int j = 1; j <= cnt && 1ll * p[j] * p[j] <= w; j++) {
            if (w % p[j] == 0) {
                int cnt = 0;
                while (w % p[j] == 0) w /= p[j], cnt++;
                mx[j] = max(mx[j], cnt);
                // cout << p[j] << ' ' << cnt << '\n';
            }
        }
        if (w != 1) mx[id[w]] = max(mx[id[w]], 1);
    }
    int ans = 1;
    for (int i = 1; i <= cnt; i++) {
        if (mx[i] == 0) continue;
        ans = 1ll * ans * ksm(p[i], mx[i]) % mod;
    }
    cout << ans << '\n';
    QwQ3301AwA;
}

详细

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

Test #1:

score: 10
Accepted
time: 12ms
memory: 6456kb

input:

10000
2290 3392 196 1603 181826 420 10388 168315 370440 6360 458 1588 768 188160 17640 428760 30870 ...

output:

136554595

result:

ok single line: '136554595'

Test #2:

score: 10
Accepted
time: 6ms
memory: 6452kb

input:

10000
467712 12250 505344 261000 2016 2360 821280 519680 132160 2961 371200 141 26019 682080 5782 13...

output:

378784227

result:

ok single line: '378784227'

Test #3:

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

input:

10000
720 3630 91476 9240 287301 4860 186624 1008 1296 36864 36 933120 12705 43560 672 975744 20736 ...

output:

272469645

result:

ok single line: '272469645'

Test #4:

score: 10
Accepted
time: 20ms
memory: 6760kb

input:

10000
209411 813081 102149 219907 593611 24114 959730 305867 496529 635050 21890 102981 487777 98241...

output:

686427981

result:

ok single line: '686427981'

Test #5:

score: 10
Accepted
time: 16ms
memory: 6760kb

input:

10000
325539 329221 106895 882089 718673 502890 699009 489855 430685 939232 282330 630021 287868 584...

output:

357762046

result:

ok single line: '357762046'

Test #6:

score: 10
Accepted
time: 16ms
memory: 6756kb

input:

10000
376259 910770 887448 703054 67926 981667 695184 641139 364840 276118 318577 222469 896470 3783...

output:

54112396

result:

ok single line: '54112396'

Test #7:

score: 10
Accepted
time: 516ms
memory: 6756kb

input:

1000000
492387 235422 924898 332532 192988 684636 499872 857831 331700 547597 579017 525316 696560 2...

output:

719239181

result:

ok single line: '719239181'

Test #8:

score: 10
Accepted
time: 432ms
memory: 6756kb

input:

1000000
608515 751563 705451 994713 509537 130709 463343 41819 265855 851779 839457 85060 496650 774...

output:

411167767

result:

ok single line: '411167767'

Test #9:

score: 10
Accepted
time: 345ms
memory: 6760kb

input:

1000000
691939 300407 710197 624191 858791 609486 268030 225807 200011 188665 132600 612100 329445 6...

output:

723701065

result:

ok single line: '723701065'

Test #10:

score: 10
Accepted
time: 340ms
memory: 6756kb

input:

1000000
30518 196518 274071 359971 550121 204862 843967 173607 619138 690754 219513 171337 183499 54...

output:

227996544

result:

ok single line: '227996544'

Extra Test:

score: 0
Extra Test Passed