Pagini recente » Monitorul de evaluare | Istoria paginii utilizator/justin-_-126 | Cod sursa (job #1594443) | Monitorul de evaluare | Cod sursa (job #1409991)
#include<cstdio>
using namespace std;
int N;
struct str
{
int v[1009];
}dp[3];
void finish (str &x, int t)
{
while (t)
x.v[++x.v[0]] = t % 10, t /= 10;
}
str get (int x)
{
str ans;
ans.v[0] = 0;
while (x)
ans.v[++ans.v[0]] = x % 10, x /= 10;
return ans;
}
str suma (str a, str b)
{
str ras;
if (a.v[0] > b.v[0]) ras.v[0] = a.v[0];
else ras.v[0] = b.v[0];
int t = 0;
for (int i=1; i<=ras.v[0]; i++)
{
int c1 = 0, c2 = 0;
if (i <= a.v[0]) c1 = a.v[i];
if (i <= b.v[0]) c2 = b.v[i];
ras.v[i] = (c1 + c2 + t) % 10;
t = (c1 + c2 + t) / 10;
}
finish (ras, t);
return ras;
}
void afis (str x)
{
if (x.v[0] == 0)
printf ("0");
for (int i=x.v[0]; i>=1; i--)
printf ("%d", x.v[i]);
printf ("\n");
}
int main ()
{
freopen ("nunta.in", "r", stdin);
freopen ("nunta.out", "w", stdout);
scanf ("%d", &N);
dp[0] = dp[1] = get (1);
for (int i=2; i<=N; i++)
dp[i % 3] = suma (dp[(i-1) % 3], dp[(i-2) % 3]);
afis (dp[N % 3]);
return 0;
}