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 ...
随机推荐
- sql server删除重复的数据保留一条
DELETE FROM [TCX_1710_SHZJ].[dbo].[PR_BindingTray] WHERE 1=1 AND SNum in (SELECT * FROM ( (SELECT SN ...
- java8函数式编程实例
什么是函数式编程 函数式编程是java8的一大特色,也就是将函数作为一个参数传递给指定方法.别人传的要么是基本数据类型,要么就是地址引用 ,我们要穿一个“动作”. Stream 说到函数式编程,就不得 ...
- 九 三种Struts2访问Servlet方式总结
Servlet是单例的,Action是多例的. 多个程序访问Servlet只会创建一个Servlet对象,多个程序访问Action会创建对应的多个Action对象. 跳转页面可以获取对象的属性,说明使 ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 排版:设定文本小写
<!DOCTYPE html> <html> <head> <title>菜鸟教程(runoob.com)</title> <meta ...
- Python学习第十九课——类的装饰器
类的装饰器 # def deco(func): # print('==========') # return func # # # @deco #test=deco(test) # # def tes ...
- Python学习第十二课——json&pickle&XML模块&OS模块
json模块 import json dic={'name':'hanhan'} i=8 s='hello' l=[11,22] data=json.dumps(dic) #json.dumps() ...
- 利用django打造自己的工作流平台(二):疫情统计系统
相关文章: 利用django打造自己的工作流平台(一):从EXCEL到流程化运作 本文是“利用django打造自己的工作流平台”系列文章的第二篇,在自己开发的工作流平台中添加了一个用于排查统计可能受感 ...
- 123、Java面向对象之引用传递实例一
01.代码如下: package TIANPAN; class Message { private int num = 10; // 定义int基本类型的属性 public Message(int n ...
- Scrapy 框架结构及工作原理
1.下图为 Scrapy 框架的组成结构,并从数据流的角度揭示 Scrapy 的工作原理 2.首先.简单了解一下 Scrapy 框架中的各个组件 组 件 描 述 类 型 EN ...
- 吴裕雄--天生自然HADOOP操作实验学习笔记:ETL案例
实验目的 熟悉hadoop生态系统 初步了解大数据点击流分析业务 学会使用hadoop进行数据分析统计 实验原理 hadoop主要有三部分,hdfs做数据存储.mapreduce做数据计算.yarn做 ...