View Code of Problem 3696

#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 = 1; !flag[(int)pow(i, j) % 10]; j ++) {
			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 (scanf("%d", &n) != EOF) {
		if (n == 0) { printf("1\n"); continue; }
		int m = n % 10;
		if (m == 0) { printf("0\n"); continue; }
		printf("%d\n", list[m][n % (list[m].size() - 1)]);
		//cout << list[m][(n/10+1) % (list[m].size() - 1)] << endl;
	}
}

Double click to view unformatted code.


Back to problem 3696