Cod sursa(job #267455)

Utilizator DrakeDemonSebestin Dragos DrakeDemon Data 27 februarie 2009 14:38:20
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.5 kb
#include<stdio.h>

int cst,cf,x[100],poz=0,s=0;
long t,i,j,n;

int main(){

FILE *f = fopen("cifra.in","r");
FILE *g = fopen("cifra.out","w");
fscanf(f,"%d",&t);
int ok = 1;
for(i=1;i<=t;i++) {
	fscanf(f,"%d",&n);
	for(j=1;j<=n;j++){
		cf = j%10;
		cst = 1;
		while(ok){
			poz++;
			cst = cst * cf %10;
			x[poz] = cst;
			if(cst == cf)
				ok = 0;

			}
		poz = j % poz;
		s=(s+x[poz])%10;
		poz = 0;
		}
	fprintf(g,"%d\n",s);
	s= 0;
	}
fclose(f);
fclose(g);
return 0;
}