题目:求a^b*c%mod;

其中b<=10^100000;

是不是很大.....

/*当你要计算 A^B%C的时候
因为此题中的B很大,达到10^100000,所以我们应该联想到降幂公式。 降幂公式:A^B%C = A^(B%phi(C) + phi(C))%C
分两种情况:
当B<=phi(C)时,直接用快速幂计算A^B mod C
当B>phi(C)时,用快速幂计算A^(B mod phi(C)+phi(C)) mod C
*/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdlib>
using namespace std;
const int mod = 1e9+;
typedef long long ll;
ll phi(ll n) //求欧拉函数值
{
int ans=n,temp=n;
for(int i=;i*i<=temp;i++)
{
if(temp%i==)
{
ans-=ans/i;
while(temp%i== ) temp/=i;
}
}
if(temp>) ans-=ans/temp;
return ans;
}
ll mod_pow(ll x,ll n,ll mod) //快速幂
{
ll ans=;
while(n)
{
if(n%==) ans=ans*x%mod;
x=x*x%mod;
n/=;
}
return ans;
}
ll a,c;
char b[];
int main()
{
while(scanf("%lld%s%lld",&a,b,&c)!=EOF)
{
c%=mod;
a%=mod;
ll phic=phi(mod);
int i,len=strlen(b);
ll res=,ans;
for( i=;i<len;i++)
{
res=res*+b[i]-'';
if(res>phic)
break;
}
if(i==len)
{
ans=mod_pow(a,res,mod)*c%mod;
}
else
{
res=;
for(int i=;i<len;i++)
{
res=res*+b[i]-'';
res%=phic;
}
ans=mod_pow(a,res+phic,mod)*c%mod;
}
cout<<ans<<endl;
}
//cout<<mod_pow(2,3,mod);
return ;
}

欧拉函数phic以及超大数的快速幂的更多相关文章

  1. HDU 6322.Problem D. Euler Function -欧拉函数水题(假的数论题 ̄▽ ̄) (2018 Multi-University Training Contest 3 1004)

    6322.Problem D. Euler Function 题意就是找欧拉函数为合数的第n个数是什么. 欧拉函数从1到50打个表,发现规律,然后勇敢的水一下就过了. 官方题解: 代码: //1004 ...

  2. UVA10200-Prime Time/HDU2161-Primes,例题讲解,牛逼的费马小定理和欧拉函数判素数。

                                                    10200 - Prime Time 此题极坑(本菜太弱),鉴定完毕,9遍过. 题意:很简单的求一个区间 ...

  3. BZOJ 2818 GCD 【欧拉函数 || 莫比乌斯反演】

    传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=2818 2818: Gcd Time Limit: 10 Sec  Memory Limit ...

  4. 欧拉函数(小于或等于n的数中与n互质的数的数目)&& 欧拉函数线性筛法

    [欧拉函数] 在数论,对正整数n,欧拉函数是少于或等于n的数中与n互质的数的数目.此函数以其首名研究者欧拉命名,它又称为Euler’s totient function.φ函数.欧拉商数等. 例如φ( ...

  5. BZOJ 3813--奇数国(线段树&欧拉函数&乘法逆元&状态压缩)

    3813: 奇数国 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 755  Solved: 432[Submit][Status][Discuss] ...

  6. BZOJ 2705: [SDOI2012]Longge的问题 [欧拉函数]

    2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 2553  Solved: 1565[Submit][ ...

  7. BZOJ 2818: Gcd [欧拉函数 质数 线性筛]【学习笔记】

    2818: Gcd Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 4436  Solved: 1957[Submit][Status][Discuss ...

  8. poj2478 Farey Sequence (欧拉函数)

    Farey Sequence 题意:给定一个数n,求在[1,n]这个范围内两两互质的数的个数.(转化为给定一个数n,比n小且与n互质的数的个数) 知识点: 欧拉函数: 普通求法: int Euler( ...

  9. 51Nod-1136 欧拉函数

    51Nod: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1136 1136 欧拉函数 基准时间限制:1 秒 空间限制: ...

随机推荐

  1. UART学习之路(三)基于STM32F103的USART实验

    关于STM32串口的资料可以在RM0008 Reference Manual中找到,有中文版的资料.STM32F103支持5个串口,选取USART1用来实验,其对应的IO口为PA9和PA10.这次的实 ...

  2. 在Ubuntu上开启MongoDB的IP Security

    本文翻译之MongoDB官网博客,原地址:https://www.mongodb.com/blog/post/enabling-ip-security-for-mongodb-36-on-ubuntu ...

  3. Nexus Repository3安装和maven,npm配置(Linux)

    Nexus Repository下载 根据操作系统选择指定版本,本文针对Linux安装,其他的安装过程可能有所差异. https://help.sonatype.com/repomanager3/do ...

  4. IDEA 通过插件jetty-maven-plugin使用 jetty

    jetty:run -Djetty.port=8080 pom.xml配置 <build> <plugins> <plugin> <groupId>or ...

  5. 20155204 2016-2017-2 《Java程序设计》第4周学习总结

    20155204 2016-2017-2 <Java程序设计>第4周学习总结 教材学习内容总结 继承是类与类之间的联系,接口是方法与类之间的联系,多态就是指利用接口和继承来派生许多类. 有 ...

  6. 20155229 2016-2007-2 《Java程序设计》第一周学习总结

    20155229 2016-2007-2 <Java程序设计>第一周学习总结 教材学习内容总结 1~18章的提问: 第一章:怎样撰写Java才不会沦于死背API文件.使用"复制. ...

  7. 成都Uber优步司机奖励政策(4月18日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  8. OpenCV中Mat操作clone() 与copyto()的区别

    OpenCV中Mat操作clone() 与copyto()的区别 // Mat is basically a class with two data parts: the matrix header ...

  9. Django模板层之templates

    一 模版简介 你可能已经注意到我们在例子视图中返回文本的方式有点特别. 也就是说,HTML被直接硬编码在 Python代码之中. def current_datetime(request): now ...

  10. 【MYSQL用户创建报错】ERROR 1396 (HY000): Operation CREATE USER failed for 'user1'@'%'

    原文参考自:http://blog.csdn.net/u011575570/article/details/51438841 1.创建用户的时候报错ERROR 1396 (HY000): Operat ...