uva 10692 - Huge Mods 指数循环节
来源:互联网 发布:mac重新安装系统好慢 编辑:程序博客网 时间:2024/05/20 00:37
这题也是求多重指数解取模,和hdu 的2837 有点像
公式
A^x % m = A^(x%phi(m)+phi(m)) % m (x >= phi(m))
这里的A和m不一定互质,这样问题就很简单了,附上代码。
#include <stdio.h>#define LL long longconst int maxn = 1000;bool vis[maxn];int pri[maxn], num, a[22];void get_prime() {int i, j;vis[1] = 1;for(i = 2;i*i <= maxn; i++) if(!vis[i])for(j = i*i;j <= maxn;j += i)vis[j] = 1;num = 0;for(i = 2;i <= maxn; i++) if(!vis[i])pri[num++] = i;}int euler(int n) {int ans = n;for(int i = 0;i < num && pri[i]*pri[i] <= n; i++) {if(n%pri[i] == 0) {ans = ans-ans/pri[i];while(n%pri[i] == 0)n /= pri[i];}}if(n > 1)ans = ans - ans/n;return ans;}LL powmod(LL x, LL n, LL mod) {LL ret = 1;LL now = 1;for(int i = 0;i < n; i++) {now *= x;if(now >= mod)break;}if(now >= mod)now = mod;elsenow = 0;while(n) {if(n&1) ret = ret*x%mod;x = x*x%mod;n /= 2;}return ret + now;}LL Jay(LL now, LL m, LL n) {if(now == n) {if(a[now] >= m)return a[now]%m + m;return a[now];}LL cur = euler(m);LL up = Jay(now+1, cur, n);LL ans = powmod(a[now], up, m);return ans ;}char s[111];int main() {get_prime();LL n, m;int i;int cas = 1;while(scanf("%s", s) != -1 && s[0] != '#') {printf("Case #%d: ", cas++);sscanf(s, "%lld", &m);scanf("%lld", &n);for(i = 1;i <= n ;i++)scanf("%lld", &a[i]);LL ans = Jay(1, m, n);printf("%lld\n", ans%m);}return 0;}
- uva 10692 - Huge Mods 指数循环节
- UVa 10692 Huge Mods (指数循环节)
- UVa 10692 - Huge Mods(指数循环节)
- uva 10692 - Huge Mods(指数循环节)
- uva10692 - Huge Mods poj2164: Remainder Calculator 指数循环节
- Uva--10692--Huge Mods【数论】
- UVA 10692 - Huge Mods(数论)
- uva 10692 - Huge Mods(数论)
- uva 10692——Huge Mods
- UVA - 10692 Huge Mods (欧拉函数)
- 指数循环节 uva 10692
- UVa 10692 Huge Mods(快速幂)(欧拉定理)
- UVa10692,Huge Mod,数论,欧拉定理,指数循环节
- UVa10692 Huge Mods
- 指数循环节问题
- hdu4335 (指数循环节)
- 指数循环节
- 指数循环节
- C和C++的简单介绍,标准制定历程
- SVN源码服务器搭建
- 二维数组的动态分配及参数传递
- Big Event in HDU
- sql server中将一个表中的部分数据插入到另一个表中
- uva 10692 - Huge Mods 指数循环节
- 淘汰RM与RMVB的原因
- 分布式服务框架 Zookeeper -- 管理分布式环境中的数据
- 亲和数
- strstr函数
- 卸载mysql
- php中$_server的详细参数和说明
- linux下RPM工具的使用
- backbone——图解分析