#include <iostream> using namespace std; int main() { long long n,m,i,mul; while(cin >> n >> m) { mul = 1; m = m % 4; //找规律,一个数的n次方。。它的个位数四次一循环 if(!m) m += 4; for(i = 0 ; i < m ; ++i) { mul = mul * n % 10; } cout << mul % 10 << endl; } return 0; }
#include <iostream> using namespace std; int main() { long long n,m,i,mul; while(cin >> n >> m) { mul = 1; m = m % 4; //找规律,一个数的n次方。。它的个位数四次一循环 if(!m) m += 4; for(i = 0 ; i < m ; ++i) { mul = mul * n % 10; } cout << mul % 10 << endl; } return 0; }