当前位置: 代码迷 >> 综合 >> Rightmost Digit HDU - 1061 (快速幂裸题)
  详细解决方案

Rightmost Digit HDU - 1061 (快速幂裸题)

热度:47   发布时间:2023-11-06 18:24:08.0

直接套快速幂模板

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstring>
using namespace std;
int powermod(int a,int b,int c){int ans=1;a = a % c;while(b>0){if(b%2) ans = (ans * a) %c;b = b/2;a = (a * a)%c;}return ans;	
} 
int main(){int T;scanf("%d",&T);while(T--){int n;scanf("%d",&n);printf("%d\n",powermod(n,n,10));}return 0;
}