Pagini recente » Cod sursa (job #1428989) | Cod sursa (job #917183) | Cod sursa (job #1247904) | Cod sursa (job #2560987) | Cod sursa (job #2249399)
#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), i % 10);
}
g << s % 10 << "\n";
}
f.close();
g.close();
// printf("Time taken: %.2fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC);
return 0;
}