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,踩平些小坑~
[转义字符] os.path.isdir(targetPath)总是报错,以为字符串不行而是要转成file类型,尝试了很多方法还是没解决,最后发现,windows下的路径中字符串中需要转义(例子在网上 ...
- JAVA利用jxl读取Excel内容
JAVA可以利用jxl简单快速的读取文件的内容,但是由于版本限制,只能读取97-03 xls格式的Excel. import java.io.File; import java.io.FileInp ...
- java--final 类在程序中的影响
很多时候我都记不住也弄不太清楚final类在程序的中的作用到底为何,今天正好看到了,就把它记下来,省的以后忘了的时候到处找资料~ final修饰符对程序的影响总的来说有三点: (1)final可以修饰 ...
- 如何在Kubernetes里给PostgreSQL创建secret
创建一个initdb.sql文件,输入如下内容: -- This is a postgres initialization script for the postgres container. -- ...
- python图片黑白化
#!/usr/bin/env python #-*- coding:utf-8 -*- from PIL import Image im = Image.open(r"C:\Users\wa ...
- swift的特性:扩展、协议、泛型
swift的特性:扩展.协议.泛型 扩展与继承:对象的生长方式: 协议:支持 协议->类型.类型<-协议 的双向抽象: 泛型:
- ASP.NET SignalR 与LayIM配合,轻松实现网站客服聊天室(三) 激动人心的时刻到啦,实现1v1聊天
看起来挺简单,细节还是很多的,好,接上一篇,我们已经成功连接singalR服务器了,那么剩下的内容呢,就是一步一步实现聊天功能. 我们先看看缺什么东西 点击好友弹框之后,要给服务器发消息,进入组Gro ...
- pinyin4j工具类
<!-- 导入pinyin4j --> <dependency> <groupId>com.belerweb</groupId> <artifac ...
- 【洛谷P2324】[SCOI2005]骑士精神
骑士精神 题目链接 #include<iostream> #include<cstdio> using namespace std; int t,MAXD,sx,sy; ][] ...
- Android学习笔记_38_图片的拖动、缩放功能和多点触摸
一.基础知识: 引用 理论上 Android可以处理 多达256 个手指的触摸,大概只有章鱼哥能享受这种技术带来的便利.就编程人员来说,编写多点触摸和单点触摸的方式几乎一模一样.其奥秘在于Motion ...