题意:

输入正整数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(指数循环节)的更多相关文章

  1. 【题解】Huge Mods UVa 10692 欧拉定理

    题意:计算a1^( a2^( a3^( a4^( a5^(...) ) ) ) ) % m的值,输入a数组和m,不保证m是质数,不保证互质 裸的欧拉定理题目,考的就一个公式 a^b = a^( b % ...

  2. hdu 2837 Calculation 指数循环节套路题

    Calculation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. HDU 4335 What is N?(指数循环节)题解

    题意: 询问有多少数\(n\)满足\(n^{n!}\equiv b\mod p \land\ n\in[1,M]\),数据范围:\(M\leq2^{64}-1,p\leq1e5\) 思路: 这题显然要 ...

  4. hdu 5895 Mathematician QSC 指数循环节+矩阵快速幂

    Mathematician QSC Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  5. 指数循环节 求A的B次方模C

    phi(c)为欧拉函数, 欧拉定理 : 对于互质的正整数 a 和 n ,有 aφ(n)  ≡ 1 mod n  . A^x = A^(x % Phi(C) + Phi(C)) (mod C) (x & ...

  6. 指数循环节&欧拉降幂

    证明:https://www.cnblogs.com/maijing/p/5046628.html 注意使用条件(B的范围) 例题: FZU1759 HDU2837 ZOJ1674 HDU4335

  7. HDU2837 Calculation(指数循环节)题解

    题意: 已知\(f(0)=1,f(n)=(n\%10)^{f(n/10)}\),求\(f(n)\mod m\) 思路: 由扩展欧拉定理可知:当\(b>=m\)时,\(a^b\equiv a^{b ...

  8. UVA 10692 Huge Mods(指数循环节)

    指数循环节,由于a ^x = a ^(x % m + phi(m)) (mod m)仅在x >= phi(m)时成立,故应注意要判断 //by:Gavin http://www.cnblogs. ...

  9. HDU 5895 Mathematician QSC(矩阵乘法+循环节降幂+除法取模小技巧+快速幂)

    传送门:HDU 5895 Mathematician QSC 这是一篇很好的题解,我想讲的他基本都讲了http://blog.csdn.net/queuelovestack/article/detai ...

随机推荐

  1. WPF中的颜色转换

    HEX16色转Bursh: Brush brush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFF ...

  2. oracle存储过程 关于update的动态SQL-工作心得

    本随笔文章,由个人博客(鸟不拉屎)转移至博客园 发布时间: 2018 年 12 月 20 日 原地址:https://niaobulashi.com/archives/oracle-procedure ...

  3. 微信小程序-帝国cms会员系统调用

    在用户->管理会员字段,增加如下字段:openidsession_keylsktokennicknameheadimg设置用户名长度然后,在系统,系统变最设置,用户设置,将注册用户名设置长度改成 ...

  4. 工程能力之C4模型

    概述 刚在InfoQ上看到一篇介绍C4Model的文章,觉得这个模型设计的很赞,很有指导意义,做个简单的记录. Why,为什么需要架构图? ThoughtWorks中国 文章中有几句话我觉得很有道理, ...

  5. js 的filter()方法

    filter()方法使用指定的函数测试所有元素,并创建一个包含所有通过测试的元素的新数组. filter()基本语法: arr.filter(callback[, thisArg]) filter() ...

  6. [linux] lsyncd同步工具

    环境说明: 192.168.56.101 同步源 192.168.56.102 同步目标 操作系统centos 7 lsyncd项目地址:https://github.com/axkibe/lsync ...

  7. mac 上面安装 tree 命令

    相信很多使用过Linux的用户都用过tree命令,它可以像windows的文件管理器一样清楚明了的显示目录结构. 但是mac下默认是没有 tree命令的. 1.我们可以使用find命令模拟出tree命 ...

  8. excel中如何将时间戳转换为日期格式

    https://www.cnblogs.com/xueluozhangxin/p/5868225.html =TEXT((B2/1000+8*3600)/86400+70*365+19,"y ...

  9. hive的udf创建永久函数

    上传jar包到hdfs目录中, hdfs dfs -put /home/user/hive-functions.jar /user/hive/jars/hive-functions.jar   cre ...

  10. 第十二周作业_PSP总结报告

    回顾1 (1)回想一下你曾经对计算机专业的畅想 当初你是如何做出选择计算机专业的决定的?经过一个学期,你的看法改变了么,为什么? 你认为过去接触到的课程是否符合你对计算机专业的期待,为什么?经过一个学 ...