逆元(名字太多人用我就加这几个字)

生活不易,我先叹气!
诶,之前没懂逆元。
“啊这题我咋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了
震惊发现,我是傻逼 求逆元有几种方式,咳咳

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 12
    评论
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值