hdu1420 Prepared for New Acmer ——快速幂
2013-06-01 19:33
375 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1420
题目大意:
中文题。
题目思路:
赤裸裸的快速幂。呵呵
WA了几次……原因就是输入输出要用%I64d,用%lld或者类型不用LL就出错。题目本身是说要范围10^6,如果平方一下,显然就超int了,所以不能用int
题目大意:
中文题。
题目思路:
赤裸裸的快速幂。呵呵
#include <iostream> #include <cstdio> #include <cmath> #include <cstdlib> using namespace std; #define LL long long LL m; LL Po(LL a, LL b) { LL ans = 1; while (b) { if (b&1) { ans = (ans * a) % m; b--; } b /= 2; a = a * a % m; } return ans; } int main(void) { LL n, a, b; #ifndef ONLINE_JUDGE freopen("1420.in", "r", stdin); #endif scanf("%I64d", &n); while (n--) { scanf("%I64d%I64d%I64d", &a, &b, &m); printf("%I64d\n", Po(a, b)); } return 0; }
WA了几次……原因就是输入输出要用%I64d,用%lld或者类型不用LL就出错。题目本身是说要范围10^6,如果平方一下,显然就超int了,所以不能用int
相关文章推荐
- hdu 1420 Prepared for New Acmer(快速幂入门)
- HDU 1420 Prepared for New Acmer(快速幂裸题)
- HDU 1420--Prepared for New Acmer【快速幂取模】
- HDU 1420 Prepared for New Acmer【快速幂】
- HDU 1420 Prepared for New Acmer(快速幂取模)
- HDU 1420 Prepared for New Acmer(快速幂)
- hdu 1420 Prepared for New Acmer(矩阵快速幂模板)
- hdu 1420 Prepared for New Acmer
- HDU 1420 Prepared for New Acmer
- hdu1420 Prepared for New Acmer (a^i mod n)
- hdu 1420(Prepared for New Acmer)(中国剩余定理)(降幂法)
- hdu-1420-Prepared for New Acmer-递归-java
- hdu1420 Prepared for New Acmer 简单数学
- HDU 1420 Prepared for New Acmer(数学题)
- 【HDU】1420 Prepared for New Acmer(水题、取余)
- hdu-oj 1420 Prepared for New Acmer
- HDU 1420 Prepared for New Acmer
- HDU 1420 Prepared for New Acmer
- hdu 1420 Prepared for New Acmer
- hdu_1420 Prepared for New Acmer