Cod sursa(job #3183540)

Utilizator Razvan23Razvan Mosanu Razvan23 Data 12 decembrie 2023 10:45:17
Problema Datorii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.17 kb
#include <bits/stdc++.h>
using namespace std;

ifstream fin("genpascal.in");
ofstream fout("genpascal.out");

/**
1 2
1 3  2
1 4  5  2
1 5  9  7 2
1 6 14 16 9 2

Se dubleaza valoarea pe fiecare linie
Pe linia L avem suma (x+y)*2^(L-2)

a = 3 * 2 = 6 *2
            2,1
            2
     --------------
            4,2
            8,4
            6,9 * 2
            2,9,1

x = 130
a = 0,3,1

a = 2,3,6,4,5 *
    7
    -----------
    4 2 4 2 8 3
*/
int a[1000], n, x, y, L;

void Produs(int a[], int &n, int x)
{
    int i, y, tr = 0;
    for (i = 1; i <= n; i++)
    {
        y = a[i] * x + tr;
        a[i] = y % 10;
        tr = y / 10;
    }
    while (tr > 0)
    {
        a[++n] = tr % 10;
        tr /= 10;
    }
}

int main()
{
    fin >> x >> y >> L;
    x += y;
    /// construim numarul mare:
    n = 0;
    while (x > 0)
    {
        a[++n] = x % 10;
        x /= 10;
    }
    /// inmultim pe a cu 2 de L-2 ori
    L -= 2;
    while (L >= 10)
    {
        Produs(a, n, 1024);///a=a*2^10
        L -= 10;
    }
    Produs(a, n, (1 << L));
    for (int i = n; i >= 1; i--)
        fout << a[i];
    return 0;
}