华东交通大学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