Pagini recente » Cod sursa (job #3270179) | Cod sursa (job #2848040) | Monitorul de evaluare | Cod sursa (job #1691591) | Cod sursa (job #2634784)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("cifra.in");
ofstream g("cifra.out");
string s;
int pow(int a,int b)
{
b=(b-1)%4+1;
int rez=1;
while(b)
if(b%2)
{
rez=(rez*a)%10;
b--;
}
else
{
a=(a*a)%10;
b/=2;
}
return rez;
}
int rez[100];
int main()
{
for(int i=1;i<=100;i++)
rez[i]=(rez[i-1]+pow(i,i))%10;
int t;
f>>t;
int nr;
for(int test=1;test<=t;test++)
{
f>>s;
int n=s.size();
if(n>1)
nr=s[n-1]+s[n-2]*10-11*'0';
else
nr=s[n-1]-'0';
g<<rez[nr]<<'\n';
}
f.close();
g.close();
return 0;
}