题意:计算a1^( a2^( a3^( a4^( a5^(...) ) ) ) ) % m的值,输入a数组和m,不保证m是质数,不保证互质

裸的欧拉定理题目,考的就一个公式 a^b = a^( b % phi(m) + phi(m) ) ( mod m ),这个公式的前提条件是 b >= phi(m)

但是这道题并不需要判断b >= phi(m)的条件,直接用公式就能过掉,而且udebug的标程也是错的

而且我也不知道像这样的形式如何判断b >= phi(m),如果有神犇会的话欢迎教教本蒟蒻

一组叉掉std和我的程序的数据:8 2 6 2,答案是4,程序输出0。

 #include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <utility> using namespace std;
const int MAXN = ; int m, n, a[MAXN]; int phi( int x ) {
int ans = x;
for( int i = ; i*i <= x; ++i )
if( x % i == ) {
ans = ans / i * (i-);
while( x % i == ) x /= i;
}
if( x > ) ans = ans / x * (x-);
return ans;
}
int pow_mod( int a, int b, int m ) {
if( !b ) return ;
int rtn = pow_mod(a,b/,m);
rtn = rtn * rtn % m;
if( b& ) rtn = rtn * a % m;
return rtn;
} int solve( int i, int mod ) {
if( i == n- ) return a[i] % mod;
int b = solve( i+, phi(mod) ); // 这里没有判断b >= phi(mod),直接就过掉了
return pow_mod( a[i], b+phi(mod), mod );
} int main() {
int kase = ;
while( scanf( "%d", &m ) == ) {
scanf( "%d", &n );
for( int i = ; i < n; ++i ) scanf( "%d", a+i );
printf( "Case #%d: %d\n", kase++, solve(,m) );
}
return ;
}

【题解】Huge Mods UVa 10692 欧拉定理的更多相关文章

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

    题意: 输入正整数a1,a2,a3..an和模m,求a1^a2^...^an mod m 解析: #include <iostream> #include <cstdio> # ...

  2. uva 10692 - Huge Mods(数论)

    题目链接:uva 10692 - Huge Mods 题目大意:给出一个数的次方形式,就它模掉M的值. 解题思路:依据剩余系的性质,最后一定是行成周期的,所以就有ab=abmod(phi[M])+ph ...

  3. uva 10692 Huge Mods 超大数取模

    vjudge上题目链接:Huge Mods 附上截图: 题意不难理解,因为指数的范围太大,所以我就想是不是需要用求幂大法: AB % C = AB % phi(C) + phi(C) % C ( B ...

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

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

  5. UVA 10692 Huge Mod

    Problem X Huge Mod Input: standard input Output: standard output Time Limit: 1 second The operator f ...

  6. uva 10692 高次幂取模

    Huge Mod Input: standard input Output: standard output Time Limit: 1 second The operator for exponen ...

  7. UVA10692:Huge Mods

    题面 传送门 题意 输入正整数a1,a2,a3..an和模m,求a1^a2^...^an mod m Sol 首先有\[ a^b\equiv \begin{cases} a^{b\%\phi(p)}~ ...

  8. UVA-10692 Huge Mods

    题目大意:计算a1^a2^a3^a4......^an模m的值. 题目解析:幂取模运算的结果一定有周期.一旦找到周期就可把高次幂转化为低次幂.有降幂公式 (a^x)%m=(a^(x%phi(m)+ph ...

  9. 【题解】Inspection UVa 1440 LA 4597 NEERC 2009

    题目传送门:https://vjudge.net/problem/UVA-1440 看上去很像DAG的最小路径覆盖QwQ? 反正我是写了一个上下界网络流,建模方法清晰易懂. 建立源$s$,向每个原图中 ...

随机推荐

  1. jQuery用unbind方法去掉hover事件及其他方法介绍

    近日项目开发十分的繁忙,其中一个需求是实现响应式导航.(响应式的问题我们在css相关的博客中再交流) 大家都知道导航是需要下来菜单效果的,必然就会用到 jQuery的 hover() 方法.若是导航放 ...

  2. [2017 - 2018 ACL] 对话系统论文研究点整理

    (论文编号及摘要见 [2017 ACL] 对话系统. [2018 ACL Long] 对话系统. 论文标题[]中最后的数字表示截止2019.1.21 google被引次数) 1. Domain Ada ...

  3. leetcode个人题解——#20 Valid Parentheses

    class Solution { public: bool isValid(string s) { stack<char> brackts; ; i < s.size(); i++) ...

  4. nodejs promise深度解析

    Promise本质上是一个容器,内部有一个执行函数,当promise对象New出来的时候,内部包裹的函数立即执行. V8引擎会将resolve和projeccted两个函数传递进来,resolved含 ...

  5. 关于docker 基础使用记录

    Docker Hub地址:https://hub.docker.com Docker Hub 存放着 Docker 及其组件的所有资源.Docker Hub 可以帮助你与同事之间协作,并获得功能完整的 ...

  6. Automatic Judge

    Description Welcome to HDU to take part in the second CCPC girls’ competition! A new automatic judge ...

  7. 关于FEer发展方向的思考

    今天学习了HTTP权威指南这本书,虽然标题是对FEer发展的思考,不过我打算稍后再说这个议题,先对今天学习的内容做个总结. 首先:原来访问服务器的方式有多重,核心是URI,也就是统一资源定位,按照访问 ...

  8. 【TCP】- TCP协议简介

    转载:https://blog.csdn.net/ningdaxing1994/article/details/73076795 TCP 是互联网核心协议之一,本文介绍它的基础知识. 一.TCP 协议 ...

  9. wine update错误 "the cache has no package" error when wine update is available

    网址:https://bugs.launchpad.net/pipelight/+bug/1318321/

  10. 父类与子类的转换as,is

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...