Pagini recente » Cod sursa (job #2178171) | Cod sursa (job #1564839) | Cod sursa (job #1832904) | Cod sursa (job #1522343) | Cod sursa (job #771527)
Cod sursa(job #771527)
#include <fstream>
using namespace std;
int N, T1, T2, T3, S;
int x[1005];
int v[10][10][10];
void Citire () {
ifstream fin ("koba.in");
fin >> N >> T1 >> T2 >> T3;
fin.close ();
T1 %= 10;
T2 %= 10;
T3 %= 10;
v[T1][T2][T3] = 3;
x[1] = T1;
x[2] = T1 + T2;
x[3] = T1 + T2 + T3;
S = x[3];
}
int Business () {
int i, aux, per, lol;
for (i = 4; i <= N; i++)
{
aux = T3;
T3 = (T3 + T2 * T1) % 10;
T1 = T2;
T2 = aux;
if (v[T1][T2][T3])
{
lol = v[T1][T2][T3];
per = i - lol;
return (S - x[lol - 1]) * ((N - lol + 1) / per) + x[lol - 1 + (N - lol + 1) % per];
}
else
{
S += T3;
v[T1][T2][T3] = i;
x[i] = S;
}
}
return S;
}
void Scriere () {
ofstream fout ("koba.out");
if (N < 4) fout << x[N];
else fout << Business ();
fout.close ();
}
int main () {
Citire ();
Scriere ();
return 0;
}