Cod sursa(job #2108827)

Utilizator stefantagaTaga Stefan stefantaga Data 18 ianuarie 2018 20:50:00
Problema Patrate2 Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <fstream>

using namespace std;
ifstream f("patrate2.in");
ofstream g("patrate2.out");
void produs(int a[101],int b[101],int c[101])
{
    int i,t=0,j;
    c[0]=a[0]+b[0]-1;
    for (i=1;i<=a[0];i++)
    {
        for (j=1;j<=b[0];j++)
        {
            c[i+j-1]+=a[i]*b[j];
        }
    }
    for (i=1;i<=c[0];i++)
    {
        t=(c[i]+=t)/10;
        c[i]%=10;
    }
    if (t)
    {
        c[++c[0]]=t;
    }
}
int v[101],b[101],c[101],i,j,x,nn;long long n;
int main()
{

    f>>n;
    nn=n;
    n=n*n*n*2;
    while (n)
    {
        v[++v[0]]=n%10;
        n=n/10;
    }
    for (i=2;i<=nn;i++)
    {
        x=i;
        while (x)
        {
            b[++b[0]]=x%10;
            x=x/10;
        }
        produs(v,b,c);
        for (j=0;j<=c[0];j++)
        {
            v[j]=c[j];
        }
        b[0]=b[1]=b[2]=b[3]=0;
    }
    for (i=v[0];i>=1;i--)
    {
        g<<v[i];
    }
    return 0;
}