HDU/HDOJ 3609 Up-up 2010多校联合17场ZSTU
来源:互联网 发布:家里网络电视打开步骤 编辑:程序博客网 时间:2024/05/02 03:05
Up-up
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 771 Accepted Submission(s): 212
Problem Description
The Up-up of a number a by a positive integer b, denoted by a↑↑b, is recursively defined by:
a↑↑1 = a,
a↑↑(k+1) = a (a↑↑k)
Thus we have e.g. 3↑↑2 = 33 = 27, hence 3↑↑3 = 327= 7625597484987 and 3↑↑4 is roughly 103.6383346400240996*10^12
The problem is give you a pair of a and k,you must calculate a↑↑k ,the result may be large you can output the answer mod 100000000 instead
a↑↑1 = a,
a↑↑(k+1) = a (a↑↑k)
Thus we have e.g. 3↑↑2 = 33 = 27, hence 3↑↑3 = 327= 7625597484987 and 3↑↑4 is roughly 103.6383346400240996*10^12
The problem is give you a pair of a and k,you must calculate a↑↑k ,the result may be large you can output the answer mod 100000000 instead
Input
A pair of a and k .a is a positive integer and fit in __int64 and 1<=k<=200
Output
a↑↑k mod 100000000
Sample Input
3 23 3
Sample Output
2797484987
Source
2010 ACM-ICPC Multi-University Training Contest(17)——Host by ZSTU
这道题我WA了好久的说。。
先开始是5 2
10 3这两组数据过不了。。
后来改了之后还是一直WA。。
WA了10+之后我看了下discuss发现那个a和k居然可以都为0.。。。Orz。。我当时就崩溃了
不过题目也太不厚道了,都明明说了是正整数,居然还有0的情况。。。
这个题方法很简答
就是基于一个理论
a^b%c=a^(b%phi(c))%c
然后我是非递归写法和网上的主流写法貌似不一样。不过我认为要易懂一点
我的代码:
#include<stdio.h>typedef __int64 ll;ll mod=100000000;ll m[205];ll eular(ll n){ll i,ret=1;for(i=2;i*i<=n;i++){if(n%i==0){n=n/i;ret=ret*(i-1);while(n%i==0){n=n/i;ret=ret*i;}}if(n==1)break;}if(n>1)ret=ret*(n-1);return ret;}void init(){ll i;m[1]=mod;for(i=2;i<=204;i++)m[i]=eular(m[i-1]);}ll power(ll a,ll b,ll c){ll res=1; while(b) {if(b%2==1) res=res*a%c;a=(a%c)*(a%c)%c;b=b/2; } return res;}int main(){ll a,k,i,ans;init();while(scanf("%I64d%I64d",&a,&k)!=EOF){ans=a;if(a==0&&k%2==0){printf("1\n");continue;}for(i=k;i>=2;i--){ans=ans%m[i];if(ans==0)ans=m[i];ans=power(a,ans,m[i-1]);}printf("%I64d\n",ans%mod);}return 0;}
- HDU/HDOJ 3609 Up-up 2010多校联合17场ZSTU
- hdu 3609 Up-up
- 2013 多校第二场 hdu 4619 Warm up 2
- hdu 4619 Warm up 2 多校第二场
- 2013 多校第二场 hdu 4612 Warm up
- HDU/HDOJ 3875 Euclidean Algorithm 多校联合第四场
- hdu 4619 warm up 2 并查集或搜索都可以做出来的题 2013多校联合训练第二场
- HDU/HDOJ 3519 矩阵二分幂 2010多校联合第九场
- 2013多校联合2 I Warm up 2(hdu 4619)
- HDU 多校联合练习赛2 Warm up 2 二分图匹配
- HDOJ多校联合第六场
- HDOJ多校联合第四场
- HDOJ多校联合第五场
- HDU 4619 Warm up 2 (2013 多校第二场) - from lanshui_Yang
- HDU6077 Time To Get Up(模拟,2017 HDU多校联赛 第4场)
- HDU 3609 Up-up(高次降幂)
- HDU/HDOJ 3524 公式推导 2010年多校联合第九场
- HDOJ(HDU).1258 Sum It Up (DFS)
- syscore.c 源码分析
- maven axis2 pom
- 和大家分享一个显示系统时间
- 今天
- html
- HDU/HDOJ 3609 Up-up 2010多校联合17场ZSTU
- POJ 2586 Y2K Accounting Bug 贪心
- 头文件知识
- Eclipse语言包安装
- 简明 Vim 练级攻略
- SharePoint PowerShell Create Site
- Linux per_cpu 机制的详解
- bool,float,指针变量与“零值”比较的if语句
- 让JSP页面不缓存