RT,虽然和本题没什么关系。我的写法最后要把答案除以二,但是在用快速幂求逆元和线性求逆元的时候,求出了两种不同的答案。
#include <bits/stdc++.h>
using namespace std;
const int mo = 19650827;
int power(int x, int y){
int ret = 1;
while (y){
if (y&1) ret = 1LL * ret * x % mo;
x = 1LL * x * x % mo;
y >>= 1;
}
return ret;
}
int main(){
printf ("%d\n", power(2, mo-2));
return 0;
}
输出:3527791
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, p, f[3000010];
int main(){
n = 2, p = 19650827;
f[1] = 1;
for (int i=2; i<=n; i++){
f[i] = (p-p/i) * f[p%i] % p;
}
printf ("%lld\n", f[n]);
return 0;
}
输出:9825414
后者是正确的。请问这是为什么呢?