Pagini recente » Cod sursa (job #657671) | Cod sursa (job #2804713) | Cod sursa (job #1840956) | Cod sursa (job #1625960) | Cod sursa (job #504355)
Cod sursa(job #504355)
#include<cstdio>
int x,xx,n,ii,a[30001],b[30001];
int main()
{
freopen("cifra.in","r",stdin);
freopen("cifra.out","w",stdout);
scanf("%d",&x);
b[0]=0; a[0]=0;
for(int i=1;i<=30000;i++)
{
ii=i%10;
if(ii==0)
{
a[i]=0;
}
else if(ii==1)
{
a[i]=1;
}
else if(ii==2)
{
if(i%4==0)
{
a[i]=6;
}
else if(i%4==1)
{
a[i]=2;
}
else if(i%4==2)
{
a[i]=4;
}
else if(i%4==3)
{
a[i]=8;
}
}
else if(ii==3)
{
if(i%4==0)
{
a[i]=1;
}
else if(i%4==1)
{
a[i]=3;
}
else if(i%4==2)
{
a[i]=9;
}
else if(i%4==3)
{
a[i]=27;
}
}
else if(ii==4)
{
if(i%4==0)
{
a[i]=6;
}
else if(i%4==1)
{
a[i]=4;
}
}
else if(ii==5)
{
a[i]=5;
}
else if(ii==6)
{
a[i]=6;
}
else if(ii==7)
{
if(i%4==0)
{
a[i]=1;
}
else if(i%4==1)
{
a[i]=7;
}
else if(i%4==2)
{
a[i]=9;
}
else if(i%4==3)
{
a[i]=3;
}
}
else if(ii==8)
{
if(i%4==0)
{
a[i]=6;
}
else if(i%4==1)
{
a[i]=8;
}
else if(i%4==2)
{
a[i]=4;
}
else if(i%4==3)
{
a[i]=2;
}
}
else if(ii==9)
{
if(i%4==0)
{
a[i]=1;
}
else if(i%4==1)
{
a[i]=9;
}
}
b[i]=(b[i-1]+a[i])%10;
}
for(xx=1;xx<=x;xx++)
{
scanf("%d",&n);
printf("%d\n",b[n]);
}
return 0;
}