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{\ ...
随机推荐
- flask源码解析之DispatcherMiddleware
DispatcherMiddleware作用 实现多app的应用,完成路由分发的功能 如何使用 from werkzeug.wsgi import DispatcherMiddleware from ...
- springboot 配置webservice接口
导入依赖的jar <!-- webservice cxf --> <dependency> <groupId>org.apache.cxf</groupId& ...
- Linux 服务器加入Windows AD
背景信息: Windows AD Version: Windows Server 2012 R2 zh-cn 计算机全名:hlm12r2n1.hlm.com 域:hlm.com 域控管理员:stone ...
- 39.oracle高级篇
标题说是高级篇,其实也就是相对于基础篇来说的,也不是很深奥,自己平时工作中也都会用到,这里回忆的并不是特别冷门的知识,不要掉以轻心,以为“高级”就觉得工作中不会用到了. 一.select into 和 ...
- Linux Shell编程、变量、控制语句
为什么要学习Shell编程 1)Linux运维工程师在进行服务器集群管理时,需要编写Shell程序来进行服务器管理. 2)对于JavaEE和Python程序员来说,工作的需要,你的老大会要求你编写一些 ...
- find查找文件命令 - Linux系统中的常用技巧整理
“find”在Linux系统中是比较常用的文件查找命令,使用方法有很多,可以拥有查找文件.文件目录.文件更新时间.文件大小.文件权限及对比文件时间.下面是整理的“find”常用方法,方便以后需要的时候 ...
- jQuery css()与class()的用法
一.css()用法: 1.设置css // css(name, value) // 修改单个样式 // name:样式名 value:样式值 $("li") .css(&quo ...
- 启动多个appium服务(同时运行多台设备)
准备: 一台真机一台模拟器(使用的是“夜神模拟器”) 先查看是否检测到设备 adb devices 由上图可看出没有检测到模拟器(夜神模拟器已开启) 可通过以下配置完成: 第一步:找到adb的 ...
- phpStudy mysql升级至5.7
1.先停止mysql服务,卸载原来的mysql (其他菜单-->服务器管理--->MySQL--->卸载服务) 2.下载MySQL你需要的版本 ZIP Archive 版本 3.解压 ...
- [Alpha]Scrum Meeting#5
github 本次会议项目由PM召开,时间为4月7日晚上10点30分 时长10分钟 任务表格 人员 昨日工作 下一步工作 木鬼 撰写博客目录 整理清明开会记录 SiMrua 模型再训练(issue#1 ...