Huge Mods UVA - 10692(指数循环节)
题意:
输入正整数a1,a2,a3..an和模m,求a1^a2^...^an mod m
解析:

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff;
LL A[maxn], num[maxn];
LL n;
char str[maxn];
LL qpow(LL a, LL b, LL m)
{
LL res = ;
while(b)
{
if(b & ) res = res * a % m;
a = a * a % m;
b >>= ;
}
return res;
} void init()
{
for(int i=; i<maxn; i++)
A[i] = i;
for(int i=; i<maxn; i++)
if(A[i] == i)
for(int j=i; j<maxn; j+=i)
A[j] = A[j]/i*(i-);
} LL dfs(LL cnt, LL m)
{
if(cnt == n-)
{
return num[cnt] % m;
}
LL phi = A[m];
LL k = dfs(cnt+, phi) + phi; //因为在上一步的快速幂中已经%phi 所有这一步不用%phi
return qpow(num[cnt], k, m);
} int main()
{
init();
int kase = ;
while(scanf("%s",str) && strcmp(str, "#"))
{
LL MOD;
sscanf(str,"%lld", &MOD);
cin>> n;
for(int i=; i<n; i++)
{
cin>> num[i];
}
printf("Case #%d: %lld\n",++kase,dfs(, MOD));
}
return ;
}
Huge Mods UVA - 10692(指数循环节)的更多相关文章
- 【题解】Huge Mods UVa 10692 欧拉定理
题意:计算a1^( a2^( a3^( a4^( a5^(...) ) ) ) ) % m的值,输入a数组和m,不保证m是质数,不保证互质 裸的欧拉定理题目,考的就一个公式 a^b = a^( b % ...
- hdu 2837 Calculation 指数循环节套路题
Calculation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 4335 What is N?(指数循环节)题解
题意: 询问有多少数\(n\)满足\(n^{n!}\equiv b\mod p \land\ n\in[1,M]\),数据范围:\(M\leq2^{64}-1,p\leq1e5\) 思路: 这题显然要 ...
- hdu 5895 Mathematician QSC 指数循环节+矩阵快速幂
Mathematician QSC Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- 指数循环节 求A的B次方模C
phi(c)为欧拉函数, 欧拉定理 : 对于互质的正整数 a 和 n ,有 aφ(n) ≡ 1 mod n . A^x = A^(x % Phi(C) + Phi(C)) (mod C) (x & ...
- 指数循环节&欧拉降幂
证明:https://www.cnblogs.com/maijing/p/5046628.html 注意使用条件(B的范围) 例题: FZU1759 HDU2837 ZOJ1674 HDU4335
- HDU2837 Calculation(指数循环节)题解
题意: 已知\(f(0)=1,f(n)=(n\%10)^{f(n/10)}\),求\(f(n)\mod m\) 思路: 由扩展欧拉定理可知:当\(b>=m\)时,\(a^b\equiv a^{b ...
- UVA 10692 Huge Mods(指数循环节)
指数循环节,由于a ^x = a ^(x % m + phi(m)) (mod m)仅在x >= phi(m)时成立,故应注意要判断 //by:Gavin http://www.cnblogs. ...
- HDU 5895 Mathematician QSC(矩阵乘法+循环节降幂+除法取模小技巧+快速幂)
传送门:HDU 5895 Mathematician QSC 这是一篇很好的题解,我想讲的他基本都讲了http://blog.csdn.net/queuelovestack/article/detai ...
随机推荐
- Fiddler抓包原来可以这么玩
Fiddler是一个抓包工具 1 解压压缩包至C\program files (x86) 2 打开C program files (x86) Fiddler Web Debugger V4.6.201 ...
- unity灯光烘焙设置详解
游戏场景中灯光照明的构成 现实生活中的光线是有反射.折射.衍射等特性的.对这些基本特性的模拟一直以来都是计算机图形图像学的重要研究方向. 在CG中,默认的照明方式都是不考虑这些光线特性的,因此出来的效 ...
- [Codeforces-888C] - K-Dominant Character
C. K-Dominant Character time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- 前端常见算法面试题之 - 从尾到头打印链表[JavaScript解法]
题目描述 输入一个链表的头结点,从尾到头反过来打印出每个结点的值 实现思路 前端工程师看到这个题目,直接想到的就是,写个while循环来遍历链表,在循环中把节点的值存储在数组中,最后在把数组倒序后,遍 ...
- FFMS2 API 译文 [原创]
FFMS2 又称 FFmpegSource2,参阅 https://github.com/FFMS/ffms2. 原文:https://github.com/FFMS/ffms2/blob/maste ...
- SSH免密登录(并且免yes交互)
问题描述:主机A使用ssh协议远程主机B,默认会开启口令认证,即输入主机B对应用户的登录密码,并且第一次登录时,主机A需验证是否接受来自主机B的公钥,输入"yes/no"完成交互. ...
- 从零系列--node爬虫利用进程池写数据
1.主进程 const http = require('http'); const fs = require('fs'); const cheerio = require('cheerio'); co ...
- [奇葩问题] Error Domain=NSURLErrorDomain Code=-1003
问题描述: 新上线的产品,ios同事拿着一串报错来找我,日志如下:err =Error Domain=NSURLErrorDomain Code=-1003 "未能找到使用指定主机名的服务器 ...
- sprint2(第四天)
由于最近网络不行,更新的代码push不上Github,组员之间又不能clone得到最新的项目,所以这几天都没有更新到Github 燃尽图
- 【探路者】Beta发布用户使用报告
用户数量:18 一.用户列表及评论. 用户序号 用户来源 用户下载软件途径 用户姓名 用户描述(信息) 使用次数 用户评价 1 张恩聚 QQ发送可运行jar包 周楠 吉林大学在读研究生 5 ...