题目链接: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. Centos7设置文件夹写入权限

    用 root 账号执行chmod命令: #chmod -R 777 dirPath 参数 -R 表示递归,dirPath及其之内的所有文件夹.文件都被改变了权限. 例子: #chmod -R 777 ...

  2. WAKE-LINUX-SOFT-linux安装,配置,基础

    1,ubuntu 1,1下载,安装 中文ubuntu站,http://cn.ubuntu.com/ 下载地址:https://www.ubuntu.com/download 安装手册:https:// ...

  3. 用AutoHotkey一键完成Xmind里的几个功能

    F5一键添加超链接(类型为主题),常规步骤:Ctrl_h打开窗口,点击[主题],激活光标到输入框. Ctrl-i一键添加截取的图片,常规步骤是:打开画图→粘贴→保存图片为文件→Xmind里Ctrl-i ...

  4. 一个自动生成awr报告的shell脚本

    最近在学习shell编程,搞一点点小工具自动完成awr报告的收集工作,方便系统出现问题时问题排查.脚本内容如下,系统收集每天开始时间6点结束时间20点的awr报告并存储在/u01/shell_t/aw ...

  5. thrift基本概念和实例

    一.thrift可以做什么 thrift是一个跨语言通信的工具,支持的语言多,而且还提供服务器端的众多网络模型,使服务端的开发可以只专于服务本身的逻辑. 二.thrift重要概念 1.processo ...

  6. IOS 蓝牙(GameKit、Core Bluetooth)

    GameKit的蓝牙开发注意 ● 只能用于iOS设备之间的连接 ● 只能用于同一个应用程序之间的连接 ● 最好别利用蓝牙发送比较大的数据 /* 关于蓝牙的数据传输  1. 一次性传送,没有中间方法,所 ...

  7. 2.Swift教程翻译系列——Swift概览

    英文版PDF下载地址http://download.csdn.net/detail/tsingheng/7480427 依照传统学习程序语言都是从hello,world開始,在Swfit里面仅仅须要一 ...

  8. python:递归函数

    1,初识递归函数 1)什么是递归函数? 在函数中自己调用自己叫做递归函数 递归函数超过一定程度会报错.---RecursionError: maximum recursion dep th excee ...

  9. 「bzoj3687: 简单题」

    题目 发现需要一个\(O(n\sum a_i )\)的做法 于是可以直接做一个背包,\(dp[i]\)表示和为\(i\)的子集是否有奇数种 \(bitset\)优化一下就好了 #include< ...

  10. Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 【逆元求组合数 && 离散化】

    任意门:http://codeforces.com/contest/689/problem/E E. Mike and Geometry Problem time limit per test 3 s ...