题目链接:uva 10692 - Huge Mods

题目大意:给出一个数的次方形式,就它模掉M的值。

解题思路:依据剩余系的性质,最后一定是行成周期的,所以就有ab=abmod(phi[M])+phi[M](phi[M]为M的欧拉函数),这样就能够依据递归去求解。

#include <cstdio>
#include <cstring>
#include <cmath> const int maxn = 15; int A[maxn], k; int pow_mod (int a, int n, int M) {
int ans = 1; while (n) {
if (n&1)
ans = ans * a % M;
a = a * a % M;
n /= 2;
}
return ans;
} int euler_phi(int n) {
int m = (int)sqrt(n+0.5);
int ans = n;
for (int i = 2; i <= m; i++) {
if (n % i == 0) {
ans = ans / i * (i-1);
while (n%i==0)
n /= i;
}
} if (n > 1)
ans = ans / n * (n - 1);
return ans;
} int solve (int d, int M) {
if (d == k - 1)
return A[d]%M; int phi = euler_phi(M);
int c = solve (d+1, phi) + phi;
return pow_mod(A[d], c, M);
} int main () {
int cas = 1;
char str[maxn]; while (scanf("%s", str) == 1 && strcmp(str, "#")) {
int M;
sscanf(str, "%d", &M);
scanf("%d", &k);
for (int i = 0; i < k; i++)
scanf("%d", &A[i]); printf("Case #%d: %d\n", cas++, solve(0, M));
}
return 0;
}

uva 10692 - Huge Mods(数论)的更多相关文章

  1. uva 10692 Huge Mods 超大数取模

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

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

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

  3. UVA 10692 Huge Mod

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

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

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

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

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

  6. UVA 10627 - Infinite Race(数论)

    UVA 10627 - Infinite Race option=com_onlinejudge&Itemid=8&page=show_problem&category=516 ...

  7. uva 10555 - Dead Fraction)(数论)

    option=com_onlinejudge&Itemid=8&category=516&page=show_problem&problem=1496" st ...

  8. uva 10560 - Minimum Weight(数论)

    题目连接:uva 10560 - Minimum Weight 题目大意:给出n,问说至少须要多少个不同重量的砝码才干称量1~n德重量,给出所选的砝码重量,而且给出k,表示有k个重量须要用上述所选的砝 ...

  9. UVA 11754 - Code Feat(数论)

    UVA 11754 - Code Feat 题目链接 题意:给定一个c个x, y1,y2,y3..yk形式,前s小的答案满足s % x在集合y1, y2, y3 ... yk中 思路:LRJ大白例题, ...

随机推荐

  1. Ext JS学习第五天 我们所熟悉的javascript(四)

    此文用来记录学习笔记: •javascript之对象.面向对象 •可能对于高级语言你可能了解甚至精通OOP面向对象,那么对于javascript你又熟悉多少呢?我们一起来学习javascript面向对 ...

  2. 移动端rem,scale动态设置

    pt:物理像素(电容屏上像素块个数) px:逻辑像素.设备独立像素 高清屏:1px = 4pt 普通屏:1px = 1pt dpr:设备像素比:(某一方向上)物理像素/逻辑像素 通常设置1rem=屏幕 ...

  3. javascript 生成页面轮播元素

    <html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    ...

  4. 通过SecureCRT和PuTTY连接臻云CentOS版云主机

    原文地址:http://jingyan.baidu.com/article/fa4125acb6648128ac7092dc.html 如何通过SecureCRT和PuTTY工具远程连接臻云CentO ...

  5. php上传文件,创建递归目录

    <?php $uid=$_REQUEST['uid']; $avatar = 'D:/avic/discuz/uc_server/data/avatar/'.get_avatar($uid, $ ...

  6. GDG shanghai programming one hour by JavaScript

    刚在昨天参加了一场JS入门编程的活动,目的就是提升对JS的兴趣. 因为是针对零基础开发者的,一上来就是“Hello World!”了 当然,想用JS输出"Hello World!" ...

  7. xcode生成的IOS安装文件的位置

    通过xcode生成可以在IOS系统下运行的文件的具体设置: 1.首先,需要有相应的程序,并且在mac下的xcode编译后,能够在模拟器中完美运行. 2.单击xcode,打开Xcode > Pre ...

  8. 设计模式 ( 十三 ) 命令模式Command(对象行为型)

    设计模式 ( 十三 ) 命令模式Command(对象行为型) 1.概述         在软件设计中,我们经常需要向某些对象发送请求,但是并不知道请求的接收者是谁,也不知道被请求的操作是哪个,我们只需 ...

  9. android4.0移植,拨号异常

    D/dalvikvm( 2274): GC_CONCURRENT freed 206K, 12% free 6571K/7431K, paused 2ms+3ms D/dalvikvm( 2274): ...

  10. servlet 将输入内容通过拼接页面的方式显示出来

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...