64pts,求调
查看原帖
64pts,求调
1495534
huangjialuo楼主2025/1/21 16:51
#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;

typedef long long ll;

//a^k%p
int qmi(int a,int k,int p)//快速幂
{

    int res = 1;
    
    while (k)
    {
        if(k & 1)res = (ll)res*a%p;
        k >>= 1;
        a = (ll) a * a % p;
    }
    
    return res;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,p;
    cin >> n >> p;
    for(int i = 1;i <= n;i ++)
    {
        cout << qmi(i,p-2,p) << "\n";
    }
    return 0;
}
2025/1/21 16:51
加载中...