Cod sursa(job #948853)

Utilizator SRaduRadu Szasz SRadu Data 11 mai 2013 19:03:45
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <fstream>

#define MAX 105

using namespace std;

int T, ans[MAX];
string S;

inline int lgput(const int &val) {
	int base = val % 10, put = val, ans = 1;
	for(; put; put >>= 1) {
		if(put & 1) {
			ans = (ans * base) % 10;
		} base = (base * base) % 10;
	} return ans;
}

void preprocess() {
	for(int i = 1; i < 100; i++) 
		ans[i] = (ans[i - 1] + lgput(i)) % 10;
}

inline int getNumber(const string &S) {
	int ans = 0;
	for(size_t i = 0; i < S.size(); i++)
		ans = (ans * 10 + S[i] - '0') % 100;
	return ans;
}

void solve() {
	ifstream in("cifra.in"); ofstream out("cifra.out");
	for(in >> T; T; T--) {
		in >> S;
		out << ans[getNumber(S)] << "\n";
	} in.close(); out.close();
}	

int main() {
	preprocess();
	solve();
}