【扩展欧拉定理(欧拉降幂)模板题】power oj 2366

power oj 2366

思路如下:
在这里插入图片描述
(PS:果然手写比打出来那些东西舒服多了)

Code

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstring>
#include<string>
#include<vector>
#include<set>
#include<stack>
#include<list>
#include<map>
#define INF 0x3f3f3f3f
#define MID l + r >> 1
#define lsn rt << 1
#define rsn rt << 1 | 1
#define Lson lsn, l, mid
#define Rson rsn, mid+1, r
#define QL Lson, ql, qr
#define QR Rson, ql, qr
#define lowbit(x) x & (-x)

using namespace std;
typedef long long ll;
typedef vector<int>:: iterator VITer;
const int maxV = 1e3 + 5;
const int maxE = 2e3 + 5;
const ll P = 1000000007;

bool Is_Prime(ll x)
{
    if ( x == 2)
        return true;
    for(ll i = 2 ; i * i <= x ; i ++)
    {
        if( x % i == 0)
            return false;
    }
    return true;
}
set<ll>st;
void prime_factor(ll x)
{
    for( ll i = 2; i <= x ; i ++)
    {
        if(Is_Prime(x))
        {
            st.insert(x);
            return ;
        }
        while(x % i == 0)
        {
            st.insert(i);
            x /= i;
        }
    }
}

ll Euler(ll x)
{
    if(x == 1) return 1;
    ll up = x, down = 1;
    prime_factor(x);
    while(!st.empty())
    {
        ll tmp = * st.begin();
        st.erase(st.begin());
        up *= (tmp - 1);
        down *= tmp;
    }
    return up / down;
}

ll fast_power(ll x, ll  y, ll p)
{
    ll base = x % p, ans = 1;
    while(y)
    {
        if(y & 1)
            ans =(ans % p) * (base % p) % p;
        base = (base % p) * (base % p) % p;
        y >>= 1;
    }
    return ans % p;
}

ll exEuler(ll x, ll y, ll p)//x^y
{
    return fast_power(x % p, y % Euler(p), p) % p;
}

int main()
{
    ll a, b, c;
    while(~scanf("%lld%lld%lld", &a, &b, &c))
    {
        printf("%lld\n", exEuler(a, exEuler(b, c, Euler(P)), P));
    }
    return 0;
}
  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值