Pagini recente » Cod sursa (job #296407) | Cod sursa (job #2659054) | Cod sursa (job #903474) | Cod sursa (job #2691441) | Cod sursa (job #809832)
Cod sursa(job #809832)
#include <fstream>
#include <cstring>
using namespace std;
int pow_mod(int baz, int exp, int mod)
{
long long result = 1, m = baz;
while (exp)
{
if (exp&1)
result = (result * m) % mod;
exp /= 2;
m = (m * m) % mod;
}
return (int) result;
}
int main ()
{
int i=0, j=0, lg=0, T=0, suma=0, sablon[100];
char N[101]="";
ifstream infile;
ofstream outfile;
memset(sablon, 0x0, sizeof(sablon));
infile.open("cifra.in");
outfile.open("cifra.out");
for (i=1; i<100; ++i)
{
suma = ((pow_mod(i, i, 10)) + suma) % 10;
sablon[i] = suma;
}
infile >> T;
infile.get();
while (T>0)
{
infile.getline(N,101);
lg = strlen(N);
if (lg!=1)
{
outfile << sablon[(N[lg-2]-'0')*10+(N[lg-1]-'0')] << endl;
}
else
{
outfile << sablon[N[0]-'0'] << endl;
}
T--;
}
infile.close();
outfile.close();
return 0;
}