Pagini recente » Cod sursa (job #2903753) | Cod sursa (job #1843051) | Cod sursa (job #2178687) | Cod sursa (job #2586164) | Cod sursa (job #1470902)
#include <iostream>
#include <fstream>
using namespace std;
int x;
int ultimacifra(int x)
{
if((x%10==1)||(x%10==5)||(x%10==6))
return x%10;
else if(x%10==4)
{
if(x%2==0)
return 6;
else
return 4;
}
else
{
if(x%4==1)
return x%10;
if(x%4==2)
return ((x%10)*(x%10))%10;
if(x%4==3)
return ((x%10)*(x%10)*(x%10))%10;
if(x%4==0)
return ((x%10)*(x%10)*(x%10)*(x%10))%10;
}
}
int main()
{
int s, i , j , n;
ifstream f("cifra.in");
ofstream g("cifra.out");
f>>n;
for(i=1; i<=n; i++)
{
f>>x;
s=0;
for(j=1; j<=x; j++)
{
s=s+ultimacifra(j);
s=s%10;
}
g<<s<<endl;
}
return 0;
}