Cod sursa(job #6832)

Utilizator dragos_dDiaconescu Dragos dragos_d Data 21 ianuarie 2007 00:06:02
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.46 kb
#include "fstream.h"

ifstream f("cifra.in");
ofstream g("cifra.out");
int main()
{long long i,j,exp,x;
 int t,cifra,q,y;

 f>>t;
 for(i=1;i<=t;i++)
 {
     f>>x;
     cifra=0;
     for(j=1;j<=x;j++)
     {
	exp=j;
	if(j>4)
	{
	exp=j%4;
	if(exp==0)
	  exp=4;
	}
     y=j;
     for(q=1;q<exp;q++)
	y=y*j;
     y=y%10;
     cifra+=y;
     cifra=cifra%10;
     }
 g<<cifra;
 g<<"\n";
 }
f.close();
g.close();
return 0;
}