94分求助!!!

P1593 因子和

Enoch2013 @ 2024-07-06 10:33:02

我不明白为什么WA了#14

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int M = 9901;
LL a, b;
map<LL, LL> m;
void fun(LL n)
{
    for (int i = 2; i <= sqrt(n); i++)
        while (n % i == 0)
        {
            m[i]++;
            n /= i;
        }
    if (n > 1)
        m[n]++;
}
LL f(LL a, LL b)
{
    LL ans = 1;
    while (b)
    {
        if (b % 2 == 1)
            ans = ans * a % M;
        a = a * a % M;
        b /= 2;
    }
    return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> a >> b;
    fun(a);
    LL ans = 1;
    for (map<LL, LL>::iterator it = m.begin(); it != m.end(); it++)
    {
        LL p = it->first, c = it->second;
        c *= b;
        if ((p - 1) % M != 0)
        {
            LL x = f(p, c + 1) - 1, y = f(p - 1, M - 2);
            ans = ans * x % M * y % M;
        }
        else
            ans = ans * (c + 1) % M;
    }
    cout << ans;
    return 0;
}

by LCH22014 @ 2024-07-06 10:51:52

@ Enoch2013 你可以去看看题解


by Enoch2013 @ 2024-07-06 16:26:06

@LCH22014 我不抄题解!!!


by Enoch2013 @ 2024-07-06 16:26:34

@LCH22014 我要正经的回答!!!


by gdutliuyun827 @ 2024-07-08 15:31:40

取模的时候要加mod,否则可能就成负数。比如: 9901 0


by xianfeixia @ 2024-10-26 21:14:40

@gdutliuyun827 厉害


|