Pagini recente » Cod sursa (job #2596282) | Cod sursa (job #3281461) | Cod sursa (job #519390) | Cod sursa (job #378446) | Cod sursa (job #791236)
Cod sursa(job #791236)
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <string.h>
#include <math.h>
using namespace std;
int rez2(long x)
{
long y,h;
int rez;
y=x;
// x=x % 10;
if(x==0) rez=0; else
if (x==1) rez=1; else
if (x==2)
{
h=y% 4;
if(h==1) rez=2;
if(h==2) rez=4;
if(h==3) rez=8;
if(h==0) rez=6;
} else
if(x==3)
{
h=y % 4;
if(h==1)rez=3; else
if(h==2)rez=9;else
if(h==3) rez=7;else
if (h==0) rez=1;
} else
if(x==4)
{
h=y % 2;
if (h==1) rez=4; else
if(h==0) rez=6;
}else
if(x==5)rez=5; else
if(x==6)rez=6; else
if (x==7) {
h=y % 4;
if(h==1) rez=7;
if (h==2) rez=9;
if (h==3) rez=3;
if (h==4) rez=1;
} else
if(x==8)
{
h=y % 4;
if(h==1)rez=8; else
if (h==2) rez=4; else
if (h==3) rez=2; else
if (h==0) rez=6;
}else
if(x=9)
{
h=y % 2;
if(h==1) rez=9; else
if(h==0) rez=1;
}
return rez;
}
int main()
{
ifstream fin("cifra.in");
ofstream fout("cifra.out");
int t;
char* nr[t];
fin>>t;
int i,j;
int suma;
int last;
long n;
for(i=0;i<t;i++)
{
nr[i]=new char[100];
fin>>nr[i];
suma=0;
n=atol(nr[i]);
for(j=1;j<=n;j++) suma=(suma+rez2(j))%10;
last=suma%10;
fout<<last<<"\n";
}
//fout<<"\n";
return 0;
}