Pagini recente » Cod sursa (job #161467) | Cod sursa (job #1503312) | Cod sursa (job #1127934) | Cod sursa (job #272857) | Cod sursa (job #2332994)
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#define NMAX 100010
using namespace std;
fstream f("cifra.in", ios::in);
fstream g("cifra.out", ios::out);
int powResult[10];
int power(int a, int b)
{
int acc = 1;
for(int i = 0; i < b; ++i)
acc *= a;
return acc;
}
void init()
{
powResult[0] = 0;
for(int i = 1; i < 10; ++i)
powResult[i] = (powResult[i - 1] + power(i, i)) % 10;
}
int main()
{
init();
int t;
string s;
f >> t;
for(int i = 0; i < t; ++i)
{
f >> s;
int lastIndice = s.length() - 1;
int lastDigit = int(s[lastIndice] - '0');
int preLastDigit = (s.length() >= 2) ? (int(s[lastIndice - 1] - '0')) : 0;
g << (powResult[lastDigit] + 7 * preLastDigit) % 10 << '\n';
}
return 0;
}