生活不易,我先嘆氣!
誒,之前沒懂逆元,
“啊這題我咋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了
震驚發現,我是傻逼 求逆元有幾種方式,咳咳
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/221079.html
標籤:其他
上一篇:C語言入門——《一維到多維陣列》
下一篇:編譯原理 語言和文法
