题目链接: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. Android图像篇

    Android的渲染分为2D渲染和3D渲染两种,当中2D渲染的引擎为Skia.3D渲染的引擎是OpenGL ES.眼下.Android支持OpenGL ES1.0和OpenGL ES 2.0两种标准. ...

  2. 机器学习笔记(三)- from Andrew Ng的教学视频

    week four: Non-linear hypotheses:Neural Networks -->x1 and x2 x1 XNOR x2 ->a1->x1 and x2;a2 ...

  3. BZOJ 2134: 单选错位( 期望 )

    第i个填到第i+1个的期望得分显然是1/max(a[i],a[i+1]).根据期望的线性性, 我们只需将每个选项的期望值累加即可. ---------------------------------- ...

  4. java基础之junit测试框架

    1.导入junit包, 2.测试方法格式 public void test_*(){} 继承  TestCase  包(keep the bar green to keep the code clea ...

  5. fancyBox简单入门

    1. 下载 fancyBox,解压后根据需要将文件复制到网页文件夹中(建议不要更改目录结构),并在网页源码中引入相应的 css 样式和 js 文件(如果更改了目录结构,引入的时候请调整相应代码,对应它 ...

  6. linux c 得到文件大小

    #include <sys/stat.h> unsigned long get_file_size(const char *path) { unsigned long filesize = ...

  7. poj1920 Towers of Hanoi

    关于汉诺塔的递归,记住一个结论是,转移n个盘子至少需要2^n-1步 #include<iostream> #include<cstdio> #include<cmath& ...

  8. SVN - 笔记

    SVN(版本控制) 1.什么是SVN · 多人共同开发同一个项目,内部最大的问题是,在比较短的时间内如果有多人同时开发同一个文件,会造成彼此的代码相互覆盖的情况发生. · 管理着随时间改变的数据,这些 ...

  9. wince下GetManifestResourceStream得到的Stream是null的解决

    问题的引入 在编程过程中遇到下面这样一个问题: 有这样一个方法: public static AlphaImage CreateFromResource(string imageResourceNam ...

  10. 修改 Mac 默认 PHP 运行环境,给 MAMP 配置全局 Composer

    在没有配置全局性的 Composer 的时候,如果你在没有安装 Composer 的目录下运行 Composer 命令,比如:create-project 系统会返回: Could not open ...