FZU:1759-Problem 1759 Super A^B mod C (欧拉降幂)
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1759
欧拉降幂是用来干啥的?例如一个问题AB mod c,当B特别大的时候int或者longlong装不下的时候需要对B mod 一个数并且不改变最终的答案,这就可以将使用欧拉降幂公式来进行计算。
公式:AB mod C == AB%φ(C) + φ(C) mod C (其实φ(c)是c的欧拉函数值),这样就是欧拉函数的使用。
#include <stdio.h>
#include <cstring>
#include <algorithm> using namespace std;
typedef long long ll;
const int maxn = 1e6+; char b[maxn];
ll a, c; ll eular(ll n) {
ll res = n;
for (ll i = ; i * i <= n; i++) {
if (n % i == ) {
n /= i;
res = res / i * (i - ); while (n % i == ) {
n /= i;
}
}
}
if (n > )
res = res / n * (n - );
return res;
} ll quickpow(ll a, ll m, ll c) {
ll ans = ;
while (m) {
if (m & )
ans = ans * a % c;
a = a * a % c;
m >>= ;
}
return ans;
} int main() {
while (scanf("%lld%s%lld", &a, b, &c) != EOF) {
ll p = eular(c);
int len = strlen(b);
ll m = ;
for (int i = ; i < len; i++) {
m = m * ;
m += b[i] - '';
m %= p;
}
m += p;
printf("%lld\n", quickpow(a, m, c));
}
}
FZU:1759-Problem 1759 Super A^B mod C (欧拉降幂)的更多相关文章
- FZU 1759 题解 欧拉降幂
本题考点:欧拉降幂 Super A^B mod C Given A,B,C, You should quickly calculate the result of A^B mod C. (1<= ...
- TOJ 3151: H1N1's Problem(欧拉降幂)
传送门:http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=3151 时间限制(普通/Java): ...
- 欧拉降幂公式 Super A^B mod C
Description Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=100000 ...
- fzu1759 Super A^B mod C 扩展欧拉定理降幂
扩展欧拉定理: \[ a^x \equiv a^{x\mathrm{\ mod\ }\varphi(p) + x \geq \varphi(p) ? \varphi(p) : 0}(\mathrm{\ ...
- 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 ...
- HDU 6322.Problem D. Euler Function -欧拉函数水题(假的数论题 ̄▽ ̄) (2018 Multi-University Training Contest 3 1004)
6322.Problem D. Euler Function 题意就是找欧拉函数为合数的第n个数是什么. 欧拉函数从1到50打个表,发现规律,然后勇敢的水一下就过了. 官方题解: 代码: //1004 ...
- 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 Super A^B mod C 指数循环节
Problem 1759 Super A^B mod C Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description G ...
- fzou 1759 Super A^B mod C
Problem 1759 Super A^B mod CAccept: 456 Submit: 1488Time Limit: 1000 mSec Memory Limit : 32768 ...
随机推荐
- ORA-07445: exception encountered: core dump [kglpin()+527]
此报错在MOS上查到了相关信息:APPLIES TO: Oracle Database - Enterprise Edition - Version 11.2.0.4 and laterInforma ...
- angular2 里父子组件传值的坑
1.如果传的是基本类型的值,子组件里改变该值,父组件无变化 2.如果传的是对象,子组件里改变对象里的变量,父组件会变化 3.如果传的是函数,this不会继续指向父组件对象了,如果需要this指向父组件 ...
- ZJOI2019Day1镇海中学游记(3.24~3.27)
前言 第一次正式参加省选!不管怎么说,虽然明知自己很弱,但还是要尽力去尝试吧! 最好能进前\(100\),不然就没法去\(Day2\)了. \(Mar\ 24th\):出发 今天,我们正式从二中向宁波 ...
- Netbackup客户端安装网络放通端口需求,及测试网络放通方法
192.168.1.101网络放通需求如下: 客户端主机 192.168.1.101 到 服务端主机 192.168.1.100 的1556.13720.13724.1378.13782这5个 ...
- 【洛谷P2168】[NOI2015]荷马史诗
荷马史诗 建一个k叉哈夫曼树,用堆维护一下 // luogu-judger-enable-o2 #include<iostream> #include<cstdio> #inc ...
- HDU1214 圆桌会议(找规律,数学)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1214 圆桌会议 Time Limit: 2000/1000 MS (Java/Others) M ...
- cuda 8.0, ssd
error info and resolution: https://github.com/weiliu89/caffe/issues/38 https://github.com/weiliu89/c ...
- JavaWeb遗漏的知识点
1. String javax.servlet.ServletContext.getRealPath(String path)方法 官方文档解释:Gets the real path correspo ...
- PL/SQL12的安装与使用
楼主比较懒,直接放一个别人的链接吧,比较全面. 大致过程就是,下载pl/sql 下载oracle instance client 然后配置oci.dll 添加 一个连接具体数据库的 ...
- c#项目总结
写了将近10年代码了,最后休息,回想了下,感觉什么都没有. 所以打算写一些总结性的文章,先写几个项目,用于c#各个方向的封装使用 最后汇总成一个完善的解决方案.所有项目都在一个解决方案FastAIFr ...