94pts #5 WA 求调

P1593 因子和

Bohan_Jiang @ 2024-10-14 19:48:59

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

char *p1, *p2, buf[1000000];
#define nc() (p1==p2 && (p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++)
inline int rd() 
{
    int x = 0, f = 1; char c = nc();
    while (c < 48 || c > 57) f = c == 47 ? -1 : 1, c = nc();
    while (c >= 48 && c <= 57) x = x * 10 + c - 48, c = nc();
    return x * f; 
}

#define int long long
#define M 9901
int p[50000005], t[50000005], res = 1;

int qpow(int x, int y) 
{
    if (!y || x == 1) return 1;
    if (y == 1) return x;
    else if (y & 1) {
        int q = qpow(x, y/2)%M;
        return q*q*x%M;
    }
    else {
        int q = qpow(x, y/2)%M;
        return q*q%M;
    }
}

signed main() 
{
//  freopen("P1593.txt", "r", stdin);
    int a = rd(), b = rd(), c = 0, aa = a; //printf("%lld\n", qpow(2, 63));
    for (int x = 2; x <= a; ++x) {
        if (!(aa%x)) {
            p[++c] = x;
            while (!(aa%x) && aa) { //for (int i = 1; i <= c; ++i) printf("%d %d\n", p[i], t[i]); 
                aa /= x;
                ++t[c];
            }
        }
    }
//  for (int i = 1; i <= c; ++i) printf("%d %d\n", p[i], t[i]); 
    for (int i = 1; i <= c; ++i) res *= p[i] % M != 1? 
                                    ((qpow(p[i]%M, b*t[i]+1)-1) * qpow((p[i]-1)%M, M-2)) % M : 
                                    (1 + b*t[i]) % M; //printf("%d ", qpow(p[i], b*t[i]+1)); 
    printf("%d", (res%M+M)%M);
    return 0;
}

|