矩阵快速幂
矩阵快速幂的学习:
https://blog.csdn.net/wust_zzwh/article/details/52058209
n>>1是指n的二进制数向右移一位
n&1等价n%2
https://vjudge.net/contest/231312#problem/F
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
typedef long long ll;
using namespace std;
ll ans=1;
void quickpow(ll x,ll n)
{
ll res=x;
while(n)
{
if(n%2==1)
{
ans*=res;
res*=res;
if(ans>9)
ans=ans%10;
if(res>9)
res=res%10;
}
else
{
res*=res;
if(res>9)
res=res%10;
}
n=n>>1;
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
ans=1;
ll n;
scanf("%I64d",&n);
quickpow(n,n);
printf("%I64d\n",ans);
}
return 0;
}
当初的梦想实现了吗,事到如今只好放弃吗~

浙公网安备 33010602011771号