【模板】乘法逆元

#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

long long n, p, ans[3000010];

int main()
{
    scanf("%lld%lld", &n, &p);
    ans[1] = 1;
    for (int i = 2; i <= n; i++)
        ans[i] = 1LL * (p - p / i) * ans[p % i] % p;
    for (int i = 1; i <= n; i++)
        printf("%lld\n", ans[i]);

    return 0;
}

 

posted @ 2017-11-10 16:46  zbtrs  阅读(164)  评论(0编辑  收藏  举报