Pagini recente » Cod sursa (job #1073632) | Cod sursa (job #737596) | Cod sursa (job #1950901) | Cod sursa (job #3181890) | Cod sursa (job #2635552)
#include <fstream>
using namespace std;
ifstream fin("cifra.in");
ofstream fout("cifra.out");
string s;
long long sp[105];
int ultima_cifra(string s){
char ch = s[s.size()-1];
int x = (int)(ch - '0');
if(x == 0)
return 0;
if(x == 1)
return 1;
if(x == 2)
return 4;
if(x == 3)
return 7;
if(x == 4)
return 6;
if(x == 5)
return 5;
if(x == 6)
return 6;
if(x == 7)
return 3;
if(x == 8)
return 6;
return 9;
}
long long lg_pow(long long base, long long exp)
{
long long pow =1;
while(exp)
{
if(exp & 1)
pow = (pow * base)%10;
base = (base * base)%10;
exp = exp>>1;
}
return pow;
}
void precalc()
{
long long i;
for(i=1;i<=100;i++)
{
sp[i] = (sp[i-1] + lg_pow(i, i))%10;
}
}
int main()
{
int t, ind;
precalc();
fin>>t;
for(int o = 1; o <= t; o++)
{
fin>>s;
if(s.size() <= 1)
ind = (int)(s[s.size()-1] - '0');
else
ind = (int)(s[s.size()-2] - '0') * 10 + (int)(s.size()-1 - '0');
fout<<sp[ind]<<"\n";
}
return 0;
}