HDU--6063--RXD and math
2017-11-19 20:33
387 查看
题目
题解:题目运用的是快速幂,主要是要找到规律,规律的出的是:输出n^k即可(可以自己带入数字尝试一下)
所以很题目很简单处理,套一个快速幂的模板就可以了
但是要注意的有两点:
1.对数取模 (实在不行,把进行处理的数都取模吧…)
2.注意数据范围(同上,直接都 long long吧…)
代码如下:
如果不了解快速幂可以点文章开头的链接。
题解:题目运用的是快速幂,主要是要找到规律,规律的出的是:输出n^k即可(可以自己带入数字尝试一下)
所以很题目很简单处理,套一个快速幂的模板就可以了
但是要注意的有两点:
1.对数取模 (实在不行,把进行处理的数都取模吧…)
2.注意数据范围(同上,直接都 long long吧…)
代码如下:
#include<cstdio> const int M=1e9+7; long long fun(long long a,long long b,int k) { long long ans=1; while(b>0) { a=a%k; if(b&1) ans=((ans%k)*(a%k))%k; b/=2; a=(a%k*a%k)%k; } return ans%k; } int main() { long long n,k; int ca=0; while((scanf("%lld%lld",&n,&k)!=EOF)) { ca++; printf("Case #%d: %lld\n",ca,fun(n,k,M)); } return 0; }
如果不了解快速幂可以点文章开头的链接。
相关文章推荐
- RXD and math HDU - 6063
- HDU 6063 RXD and math【数学】
- H - RXD and math HDU - 6063 多校第三场
- HDU 6063 17多校3 RXD and math(暴力打表题)
- (打表或数学)HDU 6063 RXD and math
- HDU 6063 RXD and math+(快速幂)+多校联赛第三场
- HDU 6063 RXD and math
- HDU 6063 RXD and math
- Hdu 6063 - RXD and math(思维)
- hdu 6063 RXD and math (规律题)
- HDU 6063 RXD and math(快速幂)
- hdu--6063 RXD and math
- HDU 6063 RXD and math 打表找规律 快速幂
- 17暑假多校联赛3.8 HDU 6063 RXD and math
- HDU 6063 RXD and math【快速幂】【打表找规律】
- 2017 多校训练第三场 HDU 6063 RXD and math
- (2017多校训练第三场)HDU - 6063 RXD and math 找规律 + 快速幂
- RXD and math(HDU 6063 快速幂)
- hdu 6063 RXD and math(快速幂)
- 多校3 HDU - 6063 RXD and math 数学