Pagini recente » Cod sursa (job #2252155) | Cod sursa (job #923082) | Cod sursa (job #686480) | Cod sursa (job #351109) | Cod sursa (job #904341)
Cod sursa(job #904341)
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
ifstream in ("cifra.in");
ofstream out("cifra.out");
int const N=10;
int const M=105;
int t,n,mat[N][N];
char x[M];
int pow(int x, int y)
{
int rez=1;
for(int i=1;i<=y;i++)
rez*=x;
return rez;
}
void completez()
{
for(int i=1;i<10;i++)
for(int j=1;j<5;j++)
{
mat[i][j]=pow(i,j);
mat[i][j]%=10;
}
for(int i=1;i<10;i++)
mat[i][0]=mat[i][4];
}
void afis()
{
for(int i=0;i<10;i++)
{
for(int j=0;j<4;j++)
out<<mat[i][j]<<" ";
out<<"\n";
}
}
void pars()
{
int fin=strlen(x);
fin--;
n=(int)(x[fin]-'0');
if(fin>0)
{n*=10; n+=(int)(x[fin-1]-'0');}
}
void calculez()
{
int rez=0;
pars();
for(long long i=1;i<=n;i++)
{rez+=mat[i%10][i%4];rez%=10;}
out<<rez<<"\n";
}
int main()
{
completez(); in>>t;
for(int i=1;i<=t;i++)
//out<<i<<"\n";
{in>>x; calculez();}
//afis();
return 0;
}