生活不易,我先叹气!
诶,之前没懂逆元。
“啊这题我咋wa了呜呜”
xx:“因为你没会逆元”
记录一下写题过程…
51nod题目链接传送门
一:
逆元:
还是别人写的好,妙啊哈哈哈,别人家的好博客
费马小定理:
费马小定理百度百科
题意如上
诶,我好菜
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
ll n;
ll qpow(ll x, ll y){
ll res = 1;
while(y){
if(y & 1){
res = res * x % mod;
}
y >>= 1;
x = x * x % mod;
}
return res % mod;
}
int main(){
cin >> n;
ll ans = 0;
ans = (qpow(3, n + 1) - 1) % mod;
ans *= qpow(2, mod - 2) % mod;
ans %= mod;
cout << ans << endl;
return 0;
}
热血沸腾的去写了几题逆元的,5555555TLE了
震惊发现,我是傻逼 求逆元有几种方式,咳咳