【题解】Huge Mods UVa 10692 欧拉定理
题意:计算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 欧拉定理的更多相关文章
- Huge Mods UVA - 10692(指数循环节)
题意: 输入正整数a1,a2,a3..an和模m,求a1^a2^...^an mod m 解析: #include <iostream> #include <cstdio> # ...
- uva 10692 - Huge Mods(数论)
题目链接:uva 10692 - Huge Mods 题目大意:给出一个数的次方形式,就它模掉M的值. 解题思路:依据剩余系的性质,最后一定是行成周期的,所以就有ab=abmod(phi[M])+ph ...
- 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 ...
- uva 10692 高次幂取模
Huge Mod Input: standard input Output: standard output Time Limit: 1 second The operator for exponen ...
- UVA10692:Huge Mods
题面 传送门 题意 输入正整数a1,a2,a3..an和模m,求a1^a2^...^an mod m Sol 首先有\[ a^b\equiv \begin{cases} a^{b\%\phi(p)}~ ...
- UVA-10692 Huge Mods
题目大意:计算a1^a2^a3^a4......^an模m的值. 题目解析:幂取模运算的结果一定有周期.一旦找到周期就可把高次幂转化为低次幂.有降幂公式 (a^x)%m=(a^(x%phi(m)+ph ...
- 【题解】Inspection UVa 1440 LA 4597 NEERC 2009
题目传送门:https://vjudge.net/problem/UVA-1440 看上去很像DAG的最小路径覆盖QwQ? 反正我是写了一个上下界网络流,建模方法清晰易懂. 建立源$s$,向每个原图中 ...
随机推荐
- 谜题 (Puzzle,ACM/ICPC World Finals 1993,UVa227)
题目描述:算法竞赛入门经典习题3-5 题目思路:模拟题 #include <stdio.h> #include <string.h> #define maxn 55 char ...
- Hbase restFul API
获取hbase版本 curl -vi -X GET -H "Accept: text/xml" http://10.8.4.46:20550/version/cluster1.2. ...
- 国内版Office365实现MFA的方案(未完)
现在二十一世纪互联版也可以实现了MFA,现在也就是2017年3月份,支持了PC,但是对移动端应用还是不支持的,请了解. 具体方法如下: 登录国内版Office365(事例为高级商业版 https:// ...
- 浪在ACM新春大作战
题目链接: # Name 补题状态 A Memory and Crow 已补 B Memory and Trident 已补 C Memory and De-Evolution 已补 D Memory ...
- HDU 3260/POJ 3827 Facer is learning to swim(DP+搜索)(2009 Asia Ningbo Regional)
Description Facer is addicted to a game called "Tidy is learning to swim". But he finds it ...
- Linux GCC编译
.a 静态库(打包文件 由多个.o文件打包而成) .c 未经过预处理的C源码 .h C头文件 .i 经过预处理的C源码(将头文件内容加载到c文件中) .o 编译之后产生的目标文件 .s 生成的汇编语言 ...
- PhotoShop基础工具 -- 移动工具
还是学点美工的东西吧, 业余爱好 比学编程还难 PS版本 : PhotoShop CS6 1. 移动工具 (1) 工具栏和属性栏 工具栏 和 属性栏 : 左侧的是工具栏, 每选中一个工具, 在菜单 ...
- Unity3D 入门 - 工作区域介绍 与 入门示例
一. 工作区域详解 1. Scence视图 (场景设计面板) scence视图简介 : 展示创建的游戏对象, 可以对所有的游戏对象进行 移动, 操作 和 放置; -- 示例 : 创建一个球体, 控制摄 ...
- 软工1816 · Alpha冲刺(2/10)
团队信息 队名:爸爸饿了 组长博客:here 作业博客:here 组员情况 组员1(组长):王彬 过去两天完成了哪些任务 与前后端敲定接口设计的细节 重新理清业务逻辑,对项目最初的设想进行一定修正 跟 ...
- lintcode-185-矩阵的之字型遍历
185-矩阵的之字型遍历 给你一个包含 m x n 个元素的矩阵 (m 行, n 列), 求该矩阵的之字型遍历. 样例 对于如下矩阵: [ [1, 2, 3, 4], [5, 6, 7, 8], [9 ...