hdu 1097(快速幂运算)

xiaoxiao2021-02-28  100

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1097 题目大意:给出a, b 两个数,要求输出pow(a, b)   (0<a,b<=2^30) 分析://。。。利用快速幂运算。。。还没想好怎么才能把快速幂运算讲清楚(留着以后填坑) ac代码 #include<cstdio> #include<iostream> using namespace std; typedef long long ll; ll pow_fast(ll a, ll b) { ll res = 1; while(b > 0) { if(b & 1)res = res * a % 10; a = a * a % 10; b = b >> 1; } return res; } int main() { ll a, b; while(scanf("%lld %lld", &a, &b) != EOF) { ll res = pow_fast(a, b); printf("%d\n", res % 10); } return 0; }
转载请注明原文地址: https://www.6miu.com/read-70214.html

最新回复(0)