提交时间:2024-01-25 09:03:19

运行 ID: 127422

#include <bits/stdc++.h> using namespace std; int p; int fp(int n, int x) { if (x==0) return 1; if (x%2==0) { long long tmp =fp(n, x/2); return tmp * tmp % p; } return fp(n, x-1)*n % p; } signed main() { while (cin >> p && p != 0) { cout << (fp(2, p-1)+1+p)%p << '\n'; } return 0; }