题目链接: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 (欧拉降幂)的更多相关文章

  1. FZU 1759 题解 欧拉降幂

    本题考点:欧拉降幂 Super A^B mod C Given A,B,C, You should quickly calculate the result of A^B mod C. (1<= ...

  2. TOJ 3151: H1N1's Problem(欧拉降幂)

    传送门:http://acm.tzc.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=3151 时间限制(普通/Java): ...

  3. 欧拉降幂公式 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 ...

  4. fzu1759 Super A^B mod C 扩展欧拉定理降幂

    扩展欧拉定理: \[ a^x \equiv a^{x\mathrm{\ mod\ }\varphi(p) + x \geq \varphi(p) ? \varphi(p) : 0}(\mathrm{\ ...

  5. 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 ...

  6. HDU 6322.Problem D. Euler Function -欧拉函数水题(假的数论题 ̄▽ ̄) (2018 Multi-University Training Contest 3 1004)

    6322.Problem D. Euler Function 题意就是找欧拉函数为合数的第n个数是什么. 欧拉函数从1到50打个表,发现规律,然后勇敢的水一下就过了. 官方题解: 代码: //1004 ...

  7. 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 ...

  8. 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 ...

  9. fzou 1759 Super A^B mod C

    Problem 1759 Super A^B mod CAccept: 456    Submit: 1488Time Limit: 1000 mSec    Memory Limit : 32768 ...

随机推荐

  1. 在Eclipse中安装JSHint插件

    离线安装 1.下载插件包 http://download.eclipsesource.com/~rsternberg/jshint-eclipse-0.9.8.20130728-0004-b94b44 ...

  2. May 16th 2017 Week 20th Tuesday

    The most fearful enemy is not having a firm conviction. 最可怕的敌人,就是没有坚强的信念. A firm conviction or belie ...

  3. nodejs理解

    一.nodejs介绍 nodejs主要体现在事件机制和异步IO,nodejs是事件驱动的: nodejs作用:js的运行环境.操作文件.链接数据库: nodejs在执行js是单线程的,但不是nodej ...

  4. 长大DeepMind第一次团队作业

    1.队名 长大DeepMind 2.队员风采 学号 姓名 擅长的技术 编程的兴趣点 希望承担的角色 一句话宣言 B20150304508 晏司举 JAVA,ssm框架,MySQL数据库 JAVA后台服 ...

  5. 一个查看UI5控件所有公有方法的小技巧

    一个很小的tip:比如我想把UI5表格控件里的每列设置成宽度根据显示的内容自适应,需要知道应该调用控件的哪个方法来实现. 一种办法当然是查SAP帮助文档,得知需要调用控件的公有方法setAutoSiz ...

  6. c++字符串初始化

    #include<string> string s1 = "abcdefg"; string s2("abcdefg");

  7. Webstorm 添加新建.vue文件功能并支持高亮vue语法和es6语法

    添加新建.vue文件功能 ①Webstorm 右上角File-Plugins 搜索vue如果没有就去下载 点击serch in repositories ②点击安装vue.js ③安装成功后点击右下角 ...

  8. (转)HTML5之渐变

    <!DOCTYPE> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta h ...

  9. GOPL第三章练习题3.3 3.4代码

    练习3.3是peak展示为红色,valley展示为蓝色. 练习3.4是将svg图像打印到浏览器中. // Copyright © 2016 Alan A. A. Donovan & Brian ...

  10. JavaScript:直接写入 HTML 输出流

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...