二次联通门 : 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 ", number[i]); } return 0; }