Cod sursa(job #199544)
Utilizator | Data | 19 iulie 2008 12:36:24 | |
---|---|---|---|
Problema | Cifra | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.42 kb |
using namespace std;
#include <iostream>
#include <fstream>
int power(int x,int y){
int d=x;
y--;
while(y--)
x=(x*d)%10;
return x;
}
int cifra(long long n){
int s=0;
while(n--)
s = s + (power(n,n))%10;
return s;
}
int main()
{
int t,s=0;
long long n;
ifstream f("cifra.in");
ofstream g("cifra.out");
f>>t;
while(t--){
f>>n;
s=(cifra(n%10))%10;
g<<s<<endl;
}
return 0;
}