Cod sursa(job #3216812)

Utilizator nicushor21Pirlog Marian Nicolae nicushor21 Data 19 martie 2024 20:48:10
Problema Sarpe Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.98 kb
#include <bits/stdc++.h>
using namespace std;
long long n[2005],a[2005],b[2005],r[2005],i,j,t;
char c;
ifstream fin("sarpe.in");
ofstream fout("sarpe.out");
int main()
{
    i=1;
    while(fin>>c){
        n[i]=c-'0';
        i++;
    }
    n[0]=i-1;
    for(i=1;i<=n[0]/2;i++)
        swap(n[i],n[n[0]-i+1]);
    for(i=0;i<=n[0];i++)
        a[i]=b[i]=n[i];
    i=1;
    while(i<=a[0]&&a[i]==0) i++;
    a[i--]--;
    for(;i>0;i--)
        a[i]=9;
    while(a[a[0]]==0)   a[0]--;
    i=1;
    while(i<=b[0]&&b[i]==0) i++;
    if(i>1){
        b[i--]--;
        for(;i>1;i--)
            b[i]=9;
        b[1]=8;
    }else{
        if(b[1]>1)  b[1]-=2;
        else{
            i=2;
            while(i<=b[0]&&b[i]==0) i++;
            b[i--]--;
            for(;i>0;i--)
                b[i]=9;
        }
    }
    while(b[b[0]]==0)   b[0]--;
    for(i=1;i<=n[0];i++){
        n[i]*=4;
    }
    t=n[1]/10; n[1]=n[1]%10; n[0]=1;
    while(t>0){
        n[0]++;
        t+=n[n[0]];
        n[n[0]]=t%10;
        t/=10;
    }
    cout<<"4n= ";
    for(i=n[0];i>0;i--)
        cout<<n[i];
    cout<<'\n';
    for(i=1;i<=a[0];i++){
        a[i]*=2;
    }
    t=a[1]/10; a[1]=a[1]%10; a[0]=1;
    while(t>0){
        a[0]++;
        t+=a[a[0]];
        a[a[0]]=t%10;
        t/=10;
    }
    cout<<"2(n-1)= ";
    for(i=a[0];i>0;i--)
        cout<<a[i];
    cout<<'\n';
    for(i=1;i<=a[0];i++){
        for(j=1;j<=b[0];j++){
            r[i+j-1]+=a[i]*b[j];
        }
    }
    t=r[1]/10; r[1]=r[1]%10; r[0]=1;
    while(t>0){
        r[0]++;
        t+=r[r[0]];
        r[r[0]]=t%10;
        t/=10;
    }
    for(i=0;i<=r[0];i++)
        a[i]=r[i];
    cout<<"2(n-2)(n-1)= ";
    for(i=a[0];i>0;i--)
        cout<<a[i];
    cout<<'\n';
    r[0]=0; t=a[1]+n[1];
    while(t>0){
        r[0]++;
        r[r[0]]=t%10;
        t/=10;
        t+=a[r[0]+1]+n[r[0]+1];
    }
    for(i=r[0];i>0;i--)
        fout<<r[i];
    return 0;
}