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 ...
随机推荐
- MD5 加密解密字符串
方法1: using System.Text; using System.Security.Cryptography; public string Hash(string toHash) { MD5C ...
- 02.当构造参数过多时使用builder模式
前言 <Effective Java>中文第三版,是一本关于Java基础的书,这本书不止一次有人推荐我看.其中包括我很喜欢的博客园博主五月的仓颉,他曾在自己的博文<给Java程序猿们 ...
- 《iOS开发实战 从入门到上架App Store(第2版)》书籍目录
第1章 开发准备 1.1 iOS 10新特性简述 1.1.1 新增触觉反馈编程接口 1.1.2 SiriKit框架的开放 1.1.3 引入Messages App 1.1.4 通知框架的整合与扩展 1 ...
- vim功能之替换和查找
vim有着强大的替换和查找功能,若能进行熟练的运用,可以让工作效率得到一个很大程度的提高. 替换 语法:[addr]s/源字符串/目的字符串/[option] [addr]表示检索范围,如: &quo ...
- MySQL之正则
八:正则匹配: 语法: select * from 表名 where 字段名 regexp "正则表达式"; PS:MySQL中正则匹配,不能使用\w等字幕作为匹配
- windows通过zip安装mysql5.7.26的一个坑
需要将my.ini的 红框的/不能写成\ 注意编码格式问题 然后 mysqld --initialize-insecure mysqld --install net start mysql
- 谈谈spring mvc与struts的区别
1.Struts2是类级别的拦截, 一个类对应一个request上下文,SpringMVC是方法级别的拦截,一个方法对应一个request上下文,而方法同时又跟一个url对应,所以说从架构本身上Spr ...
- Linux centosVMware php-fpm的pool、php-fpm慢执行日志、open_basedir
一.php-fpm的pool vim /usr/local/php/etc/php-fpm.conf//在[global]部分增加 include = etc/php-fpm.d/*.conf mkd ...
- Windows XP 常用DOS命令
winver 检查Windows版本 wmimgmt.msc 打开windows管理体系结构(WMI) wupdmgr windows更新程序 wscript windows脚本宿主设置 writ ...
- 跨服务器的SQL语句如何书写
select * into 本地库名..表名 from OPENDATASOURCE( 'SQLOLEDB', 'Data ...