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(数论)的更多相关文章
- uva 10692 Huge Mods 超大数取模
vjudge上题目链接:Huge Mods 附上截图: 题意不难理解,因为指数的范围太大,所以我就想是不是需要用求幂大法: AB % C = AB % phi(C) + phi(C) % C ( B ...
- UVA 10692 Huge Mods(指数循环节)
指数循环节,由于a ^x = a ^(x % m + phi(m)) (mod m)仅在x >= phi(m)时成立,故应注意要判断 //by:Gavin http://www.cnblogs. ...
- UVA 10692 Huge Mod
Problem X Huge Mod Input: standard input Output: standard output Time Limit: 1 second The operator f ...
- Huge Mods UVA - 10692(指数循环节)
题意: 输入正整数a1,a2,a3..an和模m,求a1^a2^...^an mod m 解析: #include <iostream> #include <cstdio> # ...
- 【题解】Huge Mods UVa 10692 欧拉定理
题意:计算a1^( a2^( a3^( a4^( a5^(...) ) ) ) ) % m的值,输入a数组和m,不保证m是质数,不保证互质 裸的欧拉定理题目,考的就一个公式 a^b = a^( b % ...
- UVA 10627 - Infinite Race(数论)
UVA 10627 - Infinite Race option=com_onlinejudge&Itemid=8&page=show_problem&category=516 ...
- uva 10555 - Dead Fraction)(数论)
option=com_onlinejudge&Itemid=8&category=516&page=show_problem&problem=1496" st ...
- uva 10560 - Minimum Weight(数论)
题目连接:uva 10560 - Minimum Weight 题目大意:给出n,问说至少须要多少个不同重量的砝码才干称量1~n德重量,给出所选的砝码重量,而且给出k,表示有k个重量须要用上述所选的砝 ...
- UVA 11754 - Code Feat(数论)
UVA 11754 - Code Feat 题目链接 题意:给定一个c个x, y1,y2,y3..yk形式,前s小的答案满足s % x在集合y1, y2, y3 ... yk中 思路:LRJ大白例题, ...
随机推荐
- C#个人笔记
1.扩展方法:类名前面加static ,方法参数前 加this,如:对string类进行扩展 public static class string { public static ...
- android: 长按删除listview的item
转自:http://www.cnblogs.com/nuistlr/archive/2012/09/07/2675649.html 首先要继承OnItemLongClickListener publi ...
- Android广播——短信拦截
MainActivity.java package com.example.broadcasttest; import android.content.Intent; import android.c ...
- IPython在Windows 7上的搭建步骤
安装篇 pip install jupyter 使用篇 启动本地notebook,打开Windows命令行,键入:ipython notebook
- 初识Channel
java.nio.channels 中的接口和类. A channel represents an open connection to an entity such as a hardware de ...
- 如何自学 Python(干货合集)
http://wenku.baidu.com/view/5108f974192e45361066f583.html
- 多线程之线程通信条件Condition
Condition是Locks锁下的还有一种线程通信之间唤醒.堵塞的实现.它以下的await,和signal可以实现Object下的wait,notify和notifyAll的所有功能,除此之外改监视 ...
- HTML5实现IP Camera网页输出
HTML5实现IP Camera网页输出 这两天做OA项目.有一个要通过IP Camera将视频流输出到浏览器端的模块.尽管如今买到的摄像头都会提供浏览器和client的实现,可是一般来说都是仅仅支持 ...
- iOS WebCore的WebEvent和EventHandler
WebEvent是iOS专有的类,负责封装和携带从UIKit得到的系统事件信息,并由WebKit层的WAKResponder子类传递到WebCore的EventHandler. UIKit层的逻辑可参 ...
- 在eclipse上安装 sdk出现的各种问题
在eclipse上下进行android开发需要 有android SDK 和ADT 一般adt版本瑶台低, 会被提示安装较高版本的ADT, 不然, SDK可能无法使用 在安装 SDK过程中出现这样 ...