fzou 1759 Super A^B mod C
Problem 1759 Super A^B mod CAccept: 456 Submit: 1488
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000000000,1<=B<=10^1000000).
Input
Output
Sample Input
Sample Output
/*
高次同余第一题: 大牛提起过这道题,当时觉得b太大了10^1000000,无从下手。
a^b%c=a^(b%phi(c))%c ,注意a==c的情况
这句话,想起了 费马小定理 a^b%c=a^(b%(c-1))%c; c是互数,a,c互质的时候。
费马小定理是一个特殊的总结吧。这个是通式。
*/ #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std; char b[]; __int64 Euler(__int64 n)
{
__int64 i,temp=n;
for(i=;i*i<=n;i++)
{
if(n%i==)
{
while(n%i==)
n=n/i;
temp=temp/i*(i-);
}
}
if(n!=) temp=temp/n*(n-);
return temp;
} __int64 power_sum2(__int64 a,__int64 n,__int64 mod)
{
__int64 ans=;
while(n)
{
if(n&)
{
ans=(ans*a)%mod;
}
n=n>>;
a=(a*a)%mod;
}
return ans;
} int main()
{
__int64 a,c,len,k,cur,i;
while(scanf("%I64d",&a)>)
{
scanf("%s",b+);
scanf("%I64d",&c);
if(a==c)
{
printf("0\n");
continue;
}
len=strlen(b+);
k=Euler(c);
for(i=,cur=;i<=len;i++)
{
cur=cur*+b[i]-'';
cur=cur%k;
}
printf("%I64d\n",power_sum2(a%c,cur,c));
}
return ;
}
fzou 1759 Super A^B mod C的更多相关文章
- FZU 1759 Super A^B mod C 指数循环节
Problem 1759 Super A^B mod C Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description G ...
- FOJ ——Problem 1759 Super A^B mod C
Problem 1759 Super A^B mod C Accept: 1368 Submit: 4639Time Limit: 1000 mSec Memory Limit : 32 ...
- FZU:1759-Problem 1759 Super A^B mod C (欧拉降幂)
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1759 欧拉降幂是用来干啥的?例如一个问题AB mod c,当B特别大的时候int或者longlong装不下的时 ...
- FZU Super A^B mod C(欧拉函数降幂)
Problem 1759 Super A^B mod C Accept: 878 Submit: 2870 Time Limit: 1000 mSec Memory Limit : 327 ...
- Day7 - B - Super A^B mod C FZU - 1759
Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000000000,1<=B ...
- Super A^B mod C (快速幂+欧拉函数+欧拉定理)
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1759 题目:Problem Description Given A,B,C, You should quick ...
- Super A^B mod C
Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000000000,1<=B ...
- K - Super A^B mod C
Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000000000,1<=B ...
- fzu1759 Super A^B mod C 扩展欧拉定理降幂
扩展欧拉定理: \[ a^x \equiv a^{x\mathrm{\ mod\ }\varphi(p) + x \geq \varphi(p) ? \varphi(p) : 0}(\mathrm{\ ...
随机推荐
- NOI2019省选模拟赛 第三场
传送门 明明没参加过却因为点进去结果狂掉\(rating\)-- \(A\) 集合 如果我们记 \[f_k=\sum_{i=1}^nT^i{n-i\choose k}\] 那么答案显然就是\(f_{k ...
- [JS] 四角度旋转特效
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ...
- HTML5语义化标签总结
1.语义化标签总结 基础布局标签 <header></header> <nav></nav> <main></main> < ...
- django 运行报错汇总
记录自己在使用django开发过程中遇到的问题,不间断更新. (1) 独立运行普通Python脚本调用django中定义的类报错 报错信息: django.core.exceptions.Improp ...
- JS使用Crypto实现AES/ECS/zero-padding加密
首先说一句,no-padding和zero-padding是一样的.他们指的是不够16位的情况补0至16位. 天知道网上为什么会出现两种叫法. 另附两个有用的网址 http://tool.chacuo ...
- Vijos 小胖的奇偶
第一遍做 #include<iostream> #include<cstdlib> #include<cstdio> #include<cstring> ...
- jackson构建复杂Map的序列化
1.序列化复杂的Map时,可能需要下面的方式 import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson. ...
- 关于Arduino串口读写HEX
每次和硬件层进行调试的时候,就容易遇到数据格式问题.这不,继上次Matlab上的hex发送后,又遇到了Arduino上接收hex,并进行对比处理的问题.由于单片机级别的处理器只能以字节形式接收,因此无 ...
- Linus' Law
Given enough eyeballs, all bugs are shallow. ------埃里克 ...
- memcached 学习笔记 4
memcached真实项目中的应用 1 缓存式的Web应用程序架构 有了缓存的支持,我们可以在传统的app层和db层之间加入cache层,每个app服务器都可以绑定一个mc, 每次数据的读取都可以从m ...