QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#718287#8980. Prime GameliaoydAC ✓357ms18092kbC++231.8kb2024-11-06 20:10:442024-11-06 20:10:46

Judging History

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

  • [2024-11-06 20:10:46]
  • 评测
  • 测评结果:AC
  • 用时:357ms
  • 内存:18092kb
  • [2024-11-06 20:10:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define vii vector<vi>
#define pb push_back
#define pir pair<int, int>
const int P = 1e9 + 7;
const int N = 1e6 + 7;
const int inf = 0x3f3f3f3f3f3f3f3f; // longlong
const int ing = 1e18;
// const int mod = 998244353;
// cout << fixed << setprecision(5) << number << endl;
// tuple
// prev(it)   next(it)
const int mod = 1e9 + 7;
int n, m;
int ax, bx, ay, by;
bool st[N];
int pr[N];
void get(int n)
{
    for (int i = 2; i <= 1e6; i++)
    {
        if (!st[i])
        {
            pr[++pr[0]] = i;
        }
        for (int j = 1; pr[j] <= 1e6 / i; j++)
        {
            st[pr[j] * i] = 1;
            if (pr[j] % i == 0)
                break;
        }
    }
    st[1] = 1;
}
void solve()
{
    cin >> n;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    get(N);
    map<int, int> mp;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        ax = a[i];
        for (int j = 1; pr[j] <= ax; j++)
        {
            if (!st[ax])
            {
                
               //cout<<i<<" "<<mp[ax]<<" "<<ax<<"\n";
                ans += (n - i+1) * (i - mp[ax]);
                mp[ax] = i;
                break;
            }
            if (ax % pr[j] == 0)
            {
                while (ax % pr[j] == 0) ax /= pr[j];
                
                //cout<<i<<" "<<mp[pr[j]]<<" "<<pr[j]<<"\n";
                ans += (n - i+1) * (i - mp[pr[j]]);
                mp[pr[j]] = i;
                
            }
        }
    }
    cout << ans << "\n";
}
signed main()
{
    cin.tie(0)->sync_with_stdio(0);
    int _ = 1;
    // cin >> _;
    while (_--)
    {
        solve();
    }
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 5180kb

input:

10
99 62 10 47 53 9 83 33 15 24

output:

248

result:

ok single line: '248'

Test #2:

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

input:

10
6 7 5 5 4 9 9 1 8 12

output:

134

result:

ok single line: '134'

Test #3:

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

input:

10
99 62 10 47 53 9 83 33 15 24

output:

248

result:

ok single line: '248'

Test #4:

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

input:

10
692137 743219 52652 45276 492360 972264 988496 117515 917868 423315

output:

521

result:

ok single line: '521'

Test #5:

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

input:

100
408775 951905 198113 227169 170826 717434 172837 379198 720110 733849 256909 997639 834222 642949 317137 409227 410206 641528 625980 937295 557730 566754 910637 716940 949428 513251 236121 195566 241377 442709 617863 89943 809036 620607 976274 444954 341290 780899 673131 169536 855557 140849 834...

output:

255236

result:

ok single line: '255236'

Test #6:

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

input:

100
620478 109788 646916 312450 22667 609293 640239 655905 216968 843038 852594 133249 544178 720291 37881 435654 196271 976771 719580 494391 767626 423169 168736 199494 80683 744612 304689 133336 547615 244143 920884 220033 820152 494269 954687 660735 882144 978008 694034 221928 706590 479076 43374...

output:

245996

result:

ok single line: '245996'

Test #7:

score: 0
Accepted
time: 352ms
memory: 16364kb

input:

1000000
709877 145493 170549 915888 2504 680394 758139 24665 365499 242644 535590 994789 297247 518365 834337 852392 945750 480961 126953 485671 11673 262033 473744 199902 743475 91856 394619 779195 616388 60537 756645 570144 510464 285494 932570 298148 627373 110058 469501 686867 559208 82153 90754...

output:

18165930450502454

result:

ok single line: '18165930450502454'

Test #8:

score: 0
Accepted
time: 338ms
memory: 18092kb

input:

1000000
860893 478239 681225 316962 864363 182240 65645 99710 897667 169988 386819 414326 898438 234948 471033 625497 483280 970391 753335 896414 967508 17677 674487 314514 188988 903881 136481 368362 590201 721042 955555 642186 413919 122356 596499 976487 942011 597783 913610 372527 494394 887475 7...

output:

18157576058820902

result:

ok single line: '18157576058820902'

Test #9:

score: 0
Accepted
time: 357ms
memory: 18060kb

input:

1000000
682691 914940 224876 701940 259190 703453 724562 125315 610833 651499 467061 312338 54505 315289 981009 354026 537801 393078 519883 575281 683896 270054 586054 950662 604015 318960 489395 436515 483899 882912 327692 406859 315828 620090 574217 242046 826953 602965 805930 547303 601515 464773...

output:

18197740784667470

result:

ok single line: '18197740784667470'

Test #10:

score: 0
Accepted
time: 342ms
memory: 16280kb

input:

1000000
755948 926490 454109 714178 831604 648864 893662 85154 458838 730588 962865 451849 942414 234072 935713 940369 883279 316863 556822 376075 542691 354956 197948 253337 97937 264721 772598 376623 487324 382703 42608 716592 777937 485770 742000 63275 113282 257134 127586 656057 475626 670569 77...

output:

18151924609137894

result:

ok single line: '18151924609137894'

Extra Test:

score: 0
Extra Test Passed