Cod sursa(job #470692)

Utilizator hendrikHendrik Lai hendrik Data 15 iulie 2010 12:04:58
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

#define REP(i,n) for (int i=0;i<(int)(n);i++)
#define N 101
int t,sum,len,f[N];
char s[N];

void open(){
	freopen("cifra.in","r",stdin);
	freopen("cifra.out","w",stdout);
}

int bigmod(int a,int b){
	if (b==0) return 1;
	if (b&1){
		return (a*bigmod(a,b-1))%10;
	}
	int x=bigmod(a,b/2);
	return (x*x)%10;
}

void input(){
	gets(s);len=strlen(s);
	REP(i,len){
		t=(t<<1)+(t<<3)+(s[i]-'0');
	}
	f[0]=0;
	REP(i,99){
		f[i+1]=f[i]+bigmod(i+1,i+1);
		f[i+1]%=10;
	}
	sum=0;
	while (gets(s)){
		len=strlen(s);
		int tmp=0;
		for (int i=max(len-2,0);i<len;i++){
			tmp=(tmp<<1)+(tmp<<3)+(s[i]-'0');
		}
		printf("%d\n",f[tmp]);
	}
}

int main(){
	open();
	input();
	//system("pause");
	return 0;
}