Pagini recente » Cod sursa (job #678738) | Istoria paginii runda/porc_revelion | Cod sursa (job #2079209) | Cod sursa (job #987888) | Cod sursa (job #472744)
Cod sursa(job #472744)
#include <cstring>
#include <fstream>
using namespace std;
const int SIZE = 100;
ifstream fin("cifra.in");
ofstream fout("cifra.out");
inline int power(int x, int y)
{
if (y == 0) return 1;
return (x * (power(x, y - 1) % 10)) % 10;
}
void PreGen();
void Read();
void Solve();
void Write();
char n[SIZE + 1];
int t, real, pg[SIZE + 1];
int main()
{
PreGen();
Read();
}
void PreGen()
{
for (int i = 1; i <= SIZE; ++i)
{
pg[i] = pg[i - 1] + power(i, i);
pg[i] %= 10;
}
}
void Read()
{
fin >> t;
fin.getline(n, SIZE);
while (t--)
{
fin.getline(n, SIZE);
Solve();
Write();
}
}
void Solve()
{
int len = strlen(n);
if (len > 1)
real = (n[len - 2] - '0') * 10 + n[len - 1] - '0';
else
real = n[len - 1] - '0';
if (real == 0) real = 100;
}
void Write()
{
fout << pg[real] << '\n';
}