Pagini recente » Statistici Costescu Nicolas-Cristian (nicohappy) | Cod sursa (job #3203695) | Cod sursa (job #295627) | Cod sursa (job #836232) | Cod sursa (job #2009159)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("cifra.in");
ofstream fout("cifra.out");
int T, ucv[11][5], dpre[30010], x;
void pre_uc()
{
for(int i=0; i<=9; i++)
{
ucv[i][1] = i;
for(int j=2; j<=4; j++){
ucv[i][j] = (ucv[i][j-1]*i) % 10;
}
ucv[i][0] = ucv[i][4];
}
}
int uc(int a)
{
int d = a%10, ex=a%4;
return ucv[d][ex];
}
void pre_proc()
{
dpre[1] = 1;
for(int i=2; i<=30001; i++)
dpre[i] = (dpre[i-1] + uc(i)) % 10;
}
int main()
{
fin >> T;
pre_uc();
pre_proc();
for(int i=1; i<=T; i++)
{
fin >> x;
fout << dpre[x]<< '\n';
}
return 0;
}