HDU 2035 快速幂
2017-07-20 10:42
162 查看
显然是快速幂的一道裸题啦。
没接触过快速幂的同学查一查吧,挺简单的。
这道题默认的mod是1000(因为它只要后3位而已)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
const int maxn=110;
const int inf=0x3f3f3f3f;
int main()
{
int n,k;
while(scanf("%d%d",&n,&k)==2&&(n||k))
{
int ans=1;
while(k)
{
if(k&1) ans=ans*n%1000;
n=n*n%1000;
k>>=1;
}
printf("%d\n",ans);
}
}
没接触过快速幂的同学查一查吧,挺简单的。
这道题默认的mod是1000(因为它只要后3位而已)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
const int maxn=110;
const int inf=0x3f3f3f3f;
int main()
{
int n,k;
while(scanf("%d%d",&n,&k)==2&&(n||k))
{
int ans=1;
while(k)
{
if(k&1) ans=ans*n%1000;
n=n*n%1000;
k>>=1;
}
printf("%d\n",ans);
}
}
相关文章推荐
- hdu 2035 人见人爱A^B (快速幂取模)
- 快速幂 hdu 2035
- HDU 2035 快速幂取模
- hdu 2035 人见人爱A^B (快速幂)
- HDU 2035 人见人爱A^B(二分求幂,快速求幂)
- Hdu 2035 人见人爱A^B【快速幂】
- hdu 2035 人见人爱A^B (快速幂)
- HDU 2035 人见人爱A^B(二分求幂,快速求幂)
- hdu 2035 快速幂
- HDU 2035 人见人爱A^B(快速幂取模 )
- hdu 2035快速幂解法
- HDU—2035—人见人爱A^B—【快速幂取模】
- HDU 2035 人见人爱A^B (快速幂取模)
- hdu 2035 人见人爱A^B(快速幂入门)
- 人见人爱A^B 【hdu-2035】【快速幂】
- HDU 2035 人见人爱A^B 快速幂取模
- hdu 2035 人见人爱A^B(两种解决方式:第二种快速幂取模)
- hdu 2035 (快速乘方)快速乘方取模
- HDU-2035-人见人爱A^B【快速幂】
- 【快速幂取模】HDU 2035---人见人爱A^B