Test instructions: Give two positive integers m,n (0<=m,n<=10^101) for the last digit of m^n
Idea: To find the law, for M words only consider single-digit line, one-digit number will not be multiplied by the carry and change, for index n table found 2,3,7,8 are in every four consecutive times a loop, 4 and 9 to 2 for the loop
So
Take the last k,n of M to take the last two bits D (judging if the positive integer divisible 4 takes the last two bits on the line, good proof), the last digit of M^n is:
Ans = (k^p)%10
p = d%4 = = 0? 4:d%4;
Expand Knowledge Points:
How can I tell if a very large number n (beyond long Long) is divisible by a very small m?
Recursion: \
S[0] = 0;
S[i] = (s[i-1]*10 + a[i])% m;
The final Judgment s[n.length-1] is equal to 0
#include <bits/stdc++.h>using namespace Std;int main () {#ifdef XXZ //Freopen ("in", "R", stdin); #endif//XXZ string m, N; while (cin>>m>>n,m+n! = "XX") { int k = M[m.length ()-1]-' 0 '; int d = (n.length () = = 1? N[0]: N[n.length ()-2]*10 + n[n.length ()-1])-' 0 '; int p = d%4 = = 0? 4:d%4; int ans = POW (k,p); cout<<ans%10<<endl; } return 0;}
UVA 10515 (single digit for m^n)