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<=10^1000000).
Input
Output
Sample Input
3 2 4
2 10 1000
Sample Output
1
24 思路:欧拉降幂板子
typedef long long LL; LL A, C;
char B[]; LL getEuler(LL x) {
LL ans = x;
for(LL i = ; i*i <= x; ++i) {
if(x % i == ) {
ans = ans / i * (i-);
while(x % i == ) x /= i;
}
}
if(x > ) ans = ans / x * (x-);
return ans;
} LL quickPow(LL a, LL b, LL p) { // a^b (modp)
LL ret = ;
while(b) {
if(b & ) ret = (ret * a) % p;
a = (a * a) % p;
b >>= ;
}
return ret;
} int main() {
ios::sync_with_stdio(false), cin.tie(NULL);
while(cin >> A >> B >> C) {
LL phi = getEuler(C);
LL num = ;
int len = strlen(B);
for(int i = ; i < len; ++i) {
num = (num * + B[i] - '');
if(num >= phi) break;
}
if(num >= phi) {
num = ;
for(int i = ; i < len; ++i)
num = (num * + B[i] - '') % phi;
cout << quickPow(A, num+phi, C) << "\n";
} else {
cout << quickPow(A, num, C) << "\n";
}
} return ;
}
Day7 - B - Super A^B mod C FZU - 1759的更多相关文章
- FZU Super A^B mod C(欧拉函数降幂)
Problem 1759 Super A^B mod C Accept: 878 Submit: 2870 Time Limit: 1000 mSec Memory Limit : 327 ...
- 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 ...
- fzou 1759 Super A^B mod C
Problem 1759 Super A^B mod CAccept: 456 Submit: 1488Time Limit: 1000 mSec Memory Limit : 32768 ...
- FZU 1759 题解 欧拉降幂
本题考点:欧拉降幂 Super A^B mod C Given A,B,C, You should quickly calculate the result of A^B mod C. (1<= ...
- FZU:1759-Problem 1759 Super A^B mod C (欧拉降幂)
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1759 欧拉降幂是用来干啥的?例如一个问题AB mod c,当B特别大的时候int或者longlong装不下的时 ...
- 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 ...
随机推荐
- GO闭包
package main import "fmt" func main() { add_func := add(1,2) fmt.Println(add_func(1,1)) fm ...
- 吴裕雄--天生自然ORACLE数据库学习笔记:优化SQL语句
create or replace procedure trun_table(table_deleted in varchar2) as --创建一个存储过程,传入一个表示表名称的参数,实现清空指定的 ...
- Nmap 使用
0×01 前言 因为今天的重点并非nmap本身的使用,主要还是想借这次机会给大家介绍一些在实战中相对比较实用的nmap脚本,所以关于nmap自身的一些基础选项就不多说了,详情可参考博客端口渗透相关文章 ...
- idea 添加 阿里代码规范
参考: https://blog.csdn.net/weixin_39220472/article/details/80077803
- windows下svn post-commit的实现
前言: 好的!在结束了上一博客教程的Subversion安装之后.我们开始了下一项工作,windows版本下 svn post-commit的实现.说实话,这方面的知识网上的知识并不是很多~~~~~~ ...
- 【PAT甲级】1024 Palindromic Number (25 分)
题意: 输入两个正整数N和K(N<=1e10,k<=100),求K次内N和N的反置相加能否得到一个回文数,输出这个数和最小的操作次数. trick: 1e10的数字相加100次可能达到1e ...
- Jquery 获取控件的值
1:通过控件的ID 获取值 $("input[name='weiKuanDate']").val(); 2:通过控件的name 获取值 $("input[name='we ...
- Systemverilog for design 笔记(五)
转载请标明出处 第一章 System Verilog过程块.任务和函数 1.1. verilog通用目的always过程块(procedural block)(可综合) always过程块的综合 ...
- 9.2.3 hadoop reduce端连接-分区分组聚合
1.1.1 reduce端连接-分区分组聚合 reduce端连接则是利用了reduce的分区功能将stationid相同的分到同一个分区,在利用reduce的分组聚合功能,将同一个st ...
- Vue源码(下篇)
上一篇是mount之前的添加一些方法,包括全局方法gloal-api,XXXMixin,initXXX,然后一切准备就绪,来到了mount阶段,这个阶段主要是 解析template 创建watcher ...