Pagini recente » Cod sursa (job #1806138) | Cod sursa (job #2467876) | Cod sursa (job #1364397) | Cod sursa (job #3150150) | Cod sursa (job #2474077)
#include <fstream>
#include <cstring>
#include <cmath>
using namespace std;
ifstream in("cifra.in");
ofstream out("cifra.out");
char s[105];
int main()
{
long long t,i,n,ucif=0,x,y,xy,beta,j,power;
in>>t;
for(i=1; i<=t; i++)
{
ucif=0;
in>>(s+1);
n=strlen(s+1);
if(n>=2)
{
x=s[n]-'0';
y=s[n-1]-'0';
xy=x*10+y;
ucif=ucif+4*(xy/20);
xy%=20;
for(j=1;j<=xy;j++)
{
if(j%4==0)
beta=4;
else
beta=j%4;
power=pow(j,beta);
ucif=(ucif+power%10)%10;
}
}
else
if(n==1)
{
x=s[n]-'0';
for(j=1;j<=x;j++)
{
if(j%4==0)
beta=4;
else
beta=j%4;
power=pow(j,beta);
ucif=(ucif+power%10)%10;
}
}
out<<ucif<<'\n';
}
return 0;
}