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 ...
随机推荐
- 笨办法学Python(三十九)
习题 39: 列表的操作 你已经学过了列表.在你学习“while 循环”的时候,你对列表进行过“追加(append)”操作,而且将列表的内容打印了出来.另外你应该还在加分习题里研究过 Python 文 ...
- Android(java)学习笔记50:通过反射获取成员变量和成员方法并且使用
1. 反射获取成员变量并且使用: (1)获取字节码文件对象: Class c = Class.forName("cn.itcast_01.Person"); (2) ...
- Python Day 15 递归、匿名函数、内置函数
阅读目录 内容回顾 生成器的send方法 递归 匿名函数 内置函数 ##内容回顾 #1.带参装饰器 - 自定义 | wraps def wrap(info) def outer1(func): fro ...
- UVA1184 Air Raid
嘟嘟嘟 最小路径覆盖板子题. 建二分图,然后跑Dinic(因为我不会匈牙利),然后ans = n - maxflow(). 主要是发一下用链前存图的写法.(好像比vector短一点) #include ...
- 【luogu P2984 [USACO10FEB]给巧克力Chocolate Giving】 题解
题目链接:https://www.luogu.org/problemnew/show/P2984 练习SPFA,把FJ当做起点,求出到所有牛的最短路,再把两个牛的相加. #include <cs ...
- 用java语言编写的简单二叉树
package com.cjonline.foundation.evisa; public class TestTree { private int data=-1; private TestTree ...
- Angularjs 数据双向绑定
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- JavaScript函数-高阶函数
JavaScript的函数其实都指向某个变量.既然变量可以指向函数,函数的参数能接收变量,那么一个函数就可以接收另一个函数作为参数,这种函数就称之为高阶函数. function add(x,y,f) ...
- spring boot 解决后台返回 json 到前台中文乱码之后出现返回json数据报错 500:no convertter for return value of type
问题描述 spring Boot 中文返回给浏览器乱码 解析成问号?? fastJson jackJson spring boot 新增配置解决后台返回 json 到前台中文乱码之后,出现返回json ...
- 课时90.div和span(掌握)
为什么在这里讲解div和span呢,而不在html中讲解呢? 因为在我们的开发中div和span一般是配合css来使用的,来完成一定的效果,来设置一些属性,在前面我们没有学习css,所以体会不到它的效 ...