QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#718209#8980. Prime GameliaoydRE 0ms0kbC++231.8kb2024-11-06 19:58:192024-11-06 19:58:22

Judging History

This is the latest submission verdict.

  • [2024-11-06 19:58:22]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 0kb
  • [2024-11-06 19:58:19]
  • Submitted

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 <= n; i++)
    {
        if (!st[i])
        {
            pr[++pr[0]] = i;
        }
        for (int j = 1; pr[j] <= n / 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])
            {
                if (!mp[ax])
                    mp[ax] = -1;
               // cout<<ax<<"\n";
                ans += (n - i) * (i - mp[ax]);
                mp[ax] = i;
                break;
            }
            if (ax % pr[j] == 0)
            {
                while (ax % pr[j] == 0) ax /= pr[j];
                if (!mp[pr[j]]) mp[pr[j]] = -1;
                ans += (n - i) * (i - mp[pr[j]]);
                mp[pr[j]] = i;
                //cout<<pr[j]<<"\n";
            }
        }
    }
    cout << ans << "\n";
}
signed main()
{
    cin.tie(0)->sync_with_stdio(0);
    int _ = 1;
    // cin >> _;
    while (_--)
    {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

10
99 62 10 47 53 9 83 33 15 24

output:


result: