LibreOJ #110. 乘法逆元

二次联通门 : LibreOJ #110. 乘法逆元

 

 

 

 

/*
    LibreOJ #110. 乘法逆元
    
    求一个数在模意义下的所有逆元 
     
*/
#include <cstdio>

void read (int &now)
{
    now = 0;
    register char word = getchar ();
    while (word < '0' || word > '9')
        word = getchar ();
    while (word >= '0' && word <= '9')
    {
        now = now * 10 + word - '0';
        word = getchar ();
    }
}

int number[1 << 22] = {0, 1};

int main (int argc, char *argv[])
{
    int N, P;
    
    read (N);
    read (P);
    
    puts ("1");
    for (int i = 2; i <= N; i ++)
    {
        number[i] = 1LL * (P - P / i) * number[P % i] % P;
        printf ("%d\n", number[i]);
    }
    
    return 0;
}

 

posted @ 2017-06-25 19:18  ZlycerQan  阅读(159)  评论(0编辑  收藏  举报