华东交通大学2016年ACM“双基”程序设计竞赛 1005

Problem Description

最近侯ry感觉自己在数学方面的造诣不忍直视;他发现他的学习速率呈一个指数函数递增,疯狂的陷入学习的泥潭,无法自拔;他的队友发现了他的学习速率y=e^(b*lna+lnc);
e是科学界非常重要而常见的常数,e=2.718281828……。
侯ry由于数学很差不会算学习数率y,现求助于学弟,感激不尽;

Input

多组数据,每组数据输入三个整数a,b,c(a,c<=10^12,b<=10^100000)

Output

一个整数y,对10^9+7取模

Sample Input

2 3 10

Sample Output

80

Author

zhengjinke2123
解法:费马小定理降次,快速幂
#include <iostream>
#include <stdio.h>
#include <algorithm>
#define LL long long
using namespace std;
int mod=1e9+7;
LL cmd(string s)
{
    LL ans=0;
    for(int i=0; i<s.length(); i++)
    {
        ans=ans*10+s[i]-'0';
        ans%=(mod-1);
    }
    return ans;
}
LL modl(LL a, LL b, LL c)        //快速幂取余a^b%c
{
    LL res, t;
    res = 1 % c;
    t = a % c;
    while (b)
    {
        if (b & 1)
        {
            res = res * t % c;
        }
        t = t * t % c;
        b >>= 1;
    }
    return res;
}
int main()
{
    string s;
    LL a,b;
    while(cin>>a>>s>>b)
    {
        b%=mod;
        LL x=cmd(s);
        cout<<modl(a,x,mod)%mod*b%mod<<endl;
    }
    return 0;
}

  

转载于:https://www.cnblogs.com/yinghualuowu/p/6089029.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值