QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#302790#5050. ValueYcfhnndWA 1ms3512kbC++202.9kb2024-01-11 13:04:132024-01-11 13:04:14

Judging History

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

  • [2024-01-11 13:04:14]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3512kb
  • [2024-01-11 13:04:13]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;
i64 mul(i64 a, i64 b, i64 m) {
    return static_cast<__int128>(a) * b % m;
}
i64 power(i64 a, i64 b, i64 m) {
    i64 res = 1 % m;
    for (; b; b >>= 1, a = mul(a, a, m))
        if (b & 1)
            res = mul(res, a, m);
    return res;
}
bool isprime(i64 n) {
    if (n < 2)
        return false;
    static constexpr int A[] = {2, 3, 5, 7, 11, 13, 17, 19, 23};
    int s = __builtin_ctzll(n - 1);
    i64 d = (n - 1) >> s;
    for (auto a : A) {
        if (a == n)
            return true;
        i64 x = power(a, d, n);
        if (x == 1 || x == n - 1)
            continue;
        bool ok = false;
        for (int i = 0; i < s - 1; ++i) {
            x = mul(x, x, n);
            if (x == n - 1) {
                ok = true;
                break;
            }
        }
        if (!ok)
            return false;
    }
    return true;
}
vector<i64> factorize(i64 n) {
    vector<i64> p;
    function<void(i64)> f = [&](i64 n) {
        if (n <= 10000) {
            for (int i = 2; i * i <= n; ++i)
                for (; n % i == 0; n /= i)
                    p.push_back(i);
            if (n > 1)
                p.push_back(n);
            return;
        }
        if (isprime(n)) {
            p.push_back(n);
            return;
        }
        auto g = [&](i64 x) {
            return (mul(x, x, n) + 1) % n;
        };
        i64 x0 = 2;
        while (true) {
            i64 x = x0;
            i64 y = x0;
            i64 d = 1;
            i64 power = 1, lam = 0;
            i64 v = 1;
            while (d == 1) {
                y = g(y);
                ++lam;
                v = mul(v, abs(x - y), n);
                if (lam % 127 == 0) {
                    d = __gcd(v, n);
                    v = 1;
                }
                if (power == lam) {
                    x = y;
                    power *= 2;
                    lam = 0;
                    d = __gcd(v, n);
                    v = 1;
                }
            }
            if (d != n) {
                f(d);
                f(n / d);
                return;
            }
            ++x0;
        }
    };
    f(n);
    sort(p.begin(), p.end());
    return p;
}
void solve() {
    int n;
    cin >> n;
    vector<int>a(n), b(n);
    for (auto &ca : a){
        cin >> ca;
    }
    for (auto &cb : b){
        cin >> cb;
    }

    i64 ans = accumulate(a.begin(), a.end(), 0LL);
    for (int i = 1;i < n;i ++){
        vector<i64>t = factorize(i + 1);
        if (t.size() >= 2 && t[0] == t.back()){
            ans -= b[i];
        }
    }
    cout << ans << '\n';
} 

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    while (T--) {
        solve();
    }

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3512kb

input:

4
1 1 1 2
1 1 1 1

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3424kb

input:

4
1 1 1 1
1 1 1 2

output:

2

result:

wrong answer 1st numbers differ - expected: '3', found: '2'