HDU 1097

本文介绍了一种使用快速幂算法计算n^n的最后一位数的方法,并提供了一个C++实现示例。该算法通过模运算减少计算量,适用于解决大整数幂运算的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

求n^n的最后一位,快速幂,主要是留下整理的头文件

#include <bits/stdc++.h>
typedef long long ll;
typedef double db;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define sspeed  ios::sync_with_stdio(false);cin.tie(0)
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = int(1e9) + 7;
const int md=10;
ll mypow(ll a,ll e){
    if(e==0)return 1;
    return e&1?mypow(a,e-1)*a%md:mypow(a*a%md,e>>1);
}
inline ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
inline int  read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//-------- head


int main()
{
   ll a,b;
   while(cin>>a>>b) cout<<mypow(a,b)<<endl;
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值