Cod sursa(job #504589)
| Utilizator | Data | 28 noiembrie 2010 10:59:48 | |
|---|---|---|---|
| Problema | Cifra | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.47 kb |
#include<fstream.h>
#include<string.h>
#include<stdlib.h>
ifstream fin("cifra.in");
ofstream fout("cifra.out");
int be(int b,int e) {
int p=1,i;
for(i=1;i<=e;i++)
p=p*b;
return p%10;
}
int main() {
char s[201];
int n,t,i,b,e,sum,ls;
fin>>t;
while(t--) {
sum=0;
fin>>s;
ls=strlen(s);
if(ls>4) strcpy(s,s+ls-4);
n=atoi(s);
n=n%200;
for(i=1;i<=n;i++) {
b=i%10;
e=i%4;
if(e==0) e=4;
sum=sum+be(b,e);
}
sum=sum%10;
fout<<sum<<"\n";
}
return 0;
}
