Pagini recente » Monitorul de evaluare | Cod sursa (job #416459) | Cod sursa (job #962900) | Cod sursa (job #864828) | Cod sursa (job #2249401)
#include <iostream>
#include <fstream>
#include <time.h>
using namespace std;
int n;
ifstream f("cifra.in");
ofstream g("cifra.out");
int putere(int m, int j, int x)
{
if (j)
putere((m*x) % 10, j - 1, x);
else
return m%10;
}
int main()
{
clock_t tStart = clock();
int s,x,j;
f >> n;
while (!f.eof()) {
f >> n;
s = 0;
for (int i = 1; i <= n; i++)
{
x = 1;
for (j = 1; j <= i && x==1; j++)
{
if (putere(i % 10, j, i % 10) == i % 10)
{
x = 0;
// cout << j;
}
}
s += putere(i % 10, (i - 1)%j, i % 10);
}
g << s % 10 << "\n";
}
f.close();
g.close();
printf("Time taken: %.2fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC);
return 0;
}