Cod sursa(job #683197)

Utilizator andreipasalauPasalau Andrei andreipasalau Data 20 februarie 2012 10:05:26
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.36 kb
#include<fstream>
ifstream f("cifra.in");
ofstream g("cifra.out");

using namespace std;

int ultima(int numar)
{
	return numar%10;
}
int main()
{
	long T,i,k,j,u,rez;
	f>>T;
	for(i = 0; i < T; i++)
	{
		rez = 1;
		f>>k;
		for(j = 2; j <= k; j++)
		{
			u = ultima(j);
			if(u == 1)
				rez += 1;
			else if(u == 5)
				rez += 5;
			else if(u == 6)
				rez += 6;
			else if(u == 2)
			{
				if(j % 4 == 1)
					rez += 2;
				else if(j % 4 == 2)
					rez += 4;
				else if(j % 4 == 3)
					rez += 8;
				else if(j % 4 == 0)
					rez += 6;
			}
			else if (u == 3)
			{
				if(j % 4 == 1)
					rez += 3;
				else if(j % 4 == 2)
					rez += 9;
				else if(j % 4 == 3)
					rez += 7;
				else if(j % 4 == 0)
					rez += 1;
			}
			else if (u == 4)
			{
				if(j % 2 == 1)
					rez += 4;
				else
					rez += 6;
			}
			else if (u == 7)
			{
				if(j % 4 == 1)
					rez += 7;
				else if(j % 4 == 2)
					rez += 9;
				else if(j % 4 == 3)
					rez += 3;
				else if(j % 4 == 0)
					rez += 1;
			}
			else if (u == 8)
			{
				if(j % 4 == 1)
					rez += 8;
				else if(j % 4 == 2)
					rez += 4;
				else if(j % 4 == 3)
					rez += 2;
				else if(j % 4 == 0)
					rez += 6;
			}
			else if (u == 9)
			{
				if(j % 2 == 1)
					rez += 9;
				else
					rez += 1;
			}	
		}
		rez = ultima(rez);
		g<<rez<<"\n";
	}
}