题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1061 思路:快速幂 #include<iostream> #include<cstdio> #include<cstring> using namespace std; typedef long long LL; const int MOD = 1e5; LL f(LL a,LL b) { LL res=; ) { ==) res=res*a%MOD; a=a*a%MOD;…
#include <iostream>#include <cstdio>using namespace std;int mod_exp(int a, int b, int c) //快速幂取余a^b%c{ int res, t; res = 1 % c; t = a % c; while (b) { if (b & 1) { res = res * t % c; } t = t * t % c; b >>= 1; } return res;}int main()…
简单的找规律,不妨设N=10*x+a(a=N%10),那么N^N=(10*x+a)^N,用二项式展开定理可以知道N^N%10=a^N%10; 由于0<a<10,打表a^1,a^2,a^3,a^4……无论a是那个数,a^N%10最多周期为4 ; #include<iostream> using namespace std; int main() { int n, a, T; cin >> T; int p[4]; while (T--) { cin >> n…
Given a positive integer N, you should output the most right digit of N^N. Input The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case contains…