Pagini recente » Autentificare | Statistici Mircea-Andrei Albu (Mirceaeu) | Cod sursa (job #3365601) | Cod sursa (job #3365604) | Cod sursa (job #3365602)
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
using namespace std;
const int T100 = 100;
const int T20 = 20;
int f[T20];
int main()
{
ifstream fin("cifra.in");
ofstream fout("cifra.out");
int n, x, s, nr, j;
for (int i = 1; i < T20; i++)
{
int b = i % 10;
int e = i % 4;
if (e == 0)
{
e = 4;
}
int p = 1;
for (int j = 0; j < e; j++)
{
p *= b;
}
p %= 10;
f[i] = (f[i-1] + p) % 10;
}
string c;
fin >> n;
for (int i=1;i<=n;i++)
{
fin >> c;
if (c.size()==1)
{
x=c[0]-'0';
}
else
{
x = (c[c.size() - 2] - '0') * 10;
x += c[c.size() - 1] - '0';
}
int nrg = x / 20;
x = x % 20;
int s = nrg * 4;
s += f[x];
fout << s%10 << "\n";
}
fin.close();
fout.close();
return 0;
}