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{\ ...
随机推荐
- Dota2App--第三天
一.要实现的功能 1.新特性页面 1.1.是否进入新特性界面的两种情况 1)第一次安装此APP,进入新特性界面 2)不是第一次安装,但是有版本更新,进入新特性界面 1.2.具体的代码实现 //0.版本 ...
- 部署到docker容器后图片验证码显示不出来
Dockerfile如下: FROM openjdk:8-jre-alpineARG JAR_FILECOPY ${JAR_FILE} app.jarENTRYPOINT ["java&qu ...
- SPI 用户空间的读写操作
spi_device 虽然用户空间不需要直接用到spi_device结构体,但是这个结构体和用户空间的程序有密切的关系,理解它的成员有助于理解SPI设备节点的IOCTL命令,所以首先来介绍它.在内核中 ...
- Kettle 系列随笔
1.Kettle导入数据到Hive 出现多余的几行全部是null值的情况 2.Kettle根据表输入的SQL脚本返回创建表的SQL脚本 3.Kettle 行列互换之——行转列(多列数据合并成一列变为多 ...
- 多事实表 SQL实现和SSAS中MDX实现的差异
如图,资产负债视图是事实表,损益表也是事实表.都包含年.月.组织.账簿信息. SQL如何实现呢? 简单粗暴,事实事实表串事实表,Full Join select 损益视图.年 ,损益视图.年月 ,损益 ...
- Linux终端没有GUI,使用matplotlib绘图
一.解决警告信息 ... _tkinter.TclError: no display name and no $DISPLAY environment variable 两种解决方法: 1.pytho ...
- PHP正则表达式笔记和实例
转自: https://www.cnblogs.com/yafei236/p/4168290.html 本文主要介绍如何在PHP使用正则表达式,并附带几个实例. 这两天工作用到了正则表达式,发现自己 ...
- 内核诊断(二)-- patch 和diff
patch文件结构 生成patch文件 --diff命令 patch 使用 -- patch命令 3.1 打path 3.1撤销patch 使用举例 4.1 基本命令使用 4.2 内核打补丁 1. p ...
- OpenERP 疑问之一
def _get_send_amount(self,cr,uid,ids,name,args,context=None): res={} MRP={} lines = self.browse(cr,u ...
- windows下Composer因php_openssl扩展缺失而安装失败
Composer(https://getcomposer.org/)是PHP下的一个依赖管理工具.你可以在你的项目中声明你所需要用到的类库,然后Composer会在项目中为你安装它们.如果你了解Nod ...