#include<iostream> #include<vector> #include<cmath> using namespace std; int main() { vector<vector<int>> list(10); for (int i = 0; i < 10; i++) list[i].push_back(0); for (int i = 1; i < 10; i++) { int flag[10] = {}; for (int j = i; !flag[(int)pow(i, j) % 10]; j+=10) { list[i].push_back((int)pow(i, j) % 10); flag[(int)pow(i, j) % 10] = 1; } } for (int i = 0; i < 10; i++) list[i][0] = list[i][list[i].size()-1]; int n; while (cin >> n) { if (n == 0) { cout << 1 << endl; continue; } int m = n % 10; if (m == 0) { cout << 0 << endl; continue; } cout << list[m][(n/10+1) % (list[m].size() - 1)] << endl; } } |
Double click to view unformatted code.