Pagini recente » Cod sursa (job #357733) | Cod sursa (job #1742914) | Cod sursa (job #1737493) | Cod sursa (job #1340637) | Cod sursa (job #2215806)
#include <iostream>
#include <fstream>
using namespace std;
int cifre(int T){
int j,suma=0,aux,k,rest;
for(j = 1; j<=T; j++){
rest = j % 10;
aux = rest;
for( k = 1 ; k != T; k++){
aux = aux * rest % 10;
}
suma = (suma + aux) % 10;
}
return suma;
}
int main()
{
ifstream in;
in.open("cifra.in");
ofstream out;
out.open("cifra.out");
int nr,i;
in >> nr;
string str;
getline (in, str);
for(i = 0 ; i != nr; i++){
int k;
getline (in, str);
int n = str.length();
if(n == 1) k = str[n - 1] - '0';
else k = (str[n - 2] - '0') *10 + (str[n - 1] -'0');
if(k==0){
out << 0 << endl;
continue;
}
out << cifre(k) << endl;
}
}