QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#268314#7044. Easy Problem8BQube#AC ✓114ms4260kbC++201.5kb2023-11-28 15:40:562023-11-28 15:40:56

Judging History

This is the latest submission verdict.

  • [2024-10-11 10:22:02]
  • hack成功,自动添加数据
  • (/hack/947)
  • [2023-11-28 15:40:56]
  • Judged
  • Verdict: AC
  • Time: 114ms
  • Memory: 4260kb
  • [2023-11-28 15:40:56]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define SZ(a) ((int)a.size())

const int MAXM = 100005;
const int MOD = 59964251;
const int PHI = 59870352;

int pw(int a, int n) {
    if (a == 0) return 0;
    int res = 1;
    for (; n; n >>= 1, a = (ll)a * a % MOD)
        if (n & 1)
            res = (ll)res * a % MOD;
    return res;
}

void add(int &x, int val) {
    x += val;
    if (x >= MOD) x -= MOD;
}

int mu[MAXM], prime[MAXM];

void solve() {
    int n;
    int m, d, k;
    {
        string num;
        cin >> num;
        n = 0;
        for (char c : num) {
            n = ((ll)n * 10 + int(c - '0'));
            if (n >= 2 * PHI) {
                n %= PHI;
                n += PHI;
            }
        }
    }
    cin >> m >> d >> k;
    vector<int> sumk(m + 1);
    for (int i = 1; i <= m; ++i) {
        sumk[i] = pw(i, k);
        add(sumk[i], sumk[i - 1]);
    }
    int ans = 0;
    for (int i = 1; i <= m / d; ++i) {
        int val = pw((ll)pw(i * d, k) * sumk[m / (i * d)] % MOD, n);
        if (mu[i] == 1) add(ans, val);
        else if (mu[i] == -1) add(ans, MOD - val);
    }
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    mu[1] = 1;
    for (int i = 1; i < MAXM; ++i)
        for (int j = i + i; j < MAXM; j += i)
            mu[j] -= mu[i];
    int t;
    cin >> t;
    while (t--) {
        solve(); 
    }
}

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

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3816kb

input:

1
3 3 3 1

output:

27

result:

ok 1 number(s): "27"

Test #2:

score: 0
Accepted
time: 114ms
memory: 4260kb

input:

20
3 3 3 1
9109799336 6801 6178 261710951
7273901587 15151 659 409734533
2867553837 42265 22783 503178763
9393025453 49771 40281 632206641
8546649695 27578 8371 768172206
2453202595 27622 5445 542869700
334181849 61345 20134 20459578
2059563445 3141 1828 946541278
7244386143 69641 50850 906938712
89...

output:

27
20547372
8512644
59186649
51209646
43975644
44588858
9043868
30587070
44698073
3989303
8179341
37852631
19910063
45874282
20815913
47317834
21091711
47365734
49692924

result:

ok 20 numbers