码迷,mamicode.com
首页 > 其他好文 > 详细

求逆元的板子

时间:2019-12-09 19:25:52      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:sizeof   ios   size   out   std   要求   lse   c++   扩展欧几里得   

#include <bits/stdc++.h>
#include<unordered_map>

using namespace std;
typedef double dou;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;

#define pai acos(-1.0)
#define M 400050
#define inf 0x3f3f3f3f
#define Lnf 1LL<<60
#define mod 1000000007
#define IN inline
#define W(a) while(a)
#define lowbit(a) a&(-a)
#define left k<<1
#define right k<<1|1
#define lson L, mid, left
#define rson mid + 1, R, right
#define ms(a,b) memset(a,b,sizeof(a))
#define Abs(a) (a ^ (a >> 31)) - (a >> 31)
#define random(a,b) (rand()%(b+1-a)+a)
#define false_stdio ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

void exgcd(ll a, ll b, ll &x, ll &y) {//扩展欧几里得
    if (b == 0) {
        x = 1;
        y = 0;
        return;
    }
    exgcd(b, a%b, y, x);
    y -= a / b * x;
}

ll POW10(ll base, ll sup) {//十进制快速幂
    ll sum = 1LL;
    W(sup) {
        int tmp = sup % 10;
        for (int i = 1; i <= tmp; i++)sum = sum * base%mod;
        ll A = base * base%mod;
        ll B = A * A%mod;
        ll C = B * B%mod;
        base = A * C%mod;
        sup /= 10;
    }
    return sum;
}

ll POW2(ll base, ll sup) {//二进制快速幂
    ll sum = 1;
    W(sup) {
        if (sup & 1)sum = sum * base%mod;
        sup >>= 1;
        base = base * base%mod;
    }
    return sum;
}

ll solve(ll a,ll p) {//a是要求的数,p是模数
    ll x, y; 
    //exgcd(a, p, x, y); //扩展欧几里得求逆元,x为逆元
    //费马小定理求逆元
    //x = POW10(a, mod - 2);//十进制快速幂
    //x = POW2(a, mod - 2);//二进制快速幂
    x = (x + mod) % mod;
    return x;
}


int  main() {
    false_stdio;
    
    return 0;
}

求逆元的板子

标签:sizeof   ios   size   out   std   要求   lse   c++   扩展欧几里得   

原文地址:https://www.cnblogs.com/caibingxu/p/12012611.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!