Cod sursa(job #2024652)

Utilizator Vlad3108Tir Vlad Ioan Vlad3108 Data 20 septembrie 2017 22:56:32
Problema Nunta Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <cstdio>
#include <cstring>
#define LMAX 210
#define Copy(A,B) memcpy(A,B,sizeof(B))
#define Set(A) memset(A,0,sizeof(A))
using namespace std;
typedef unsigned char Huge[LMAX];
inline void Atrib(Huge &A,int x){
    Set(A);
    if(!x) A[++A[0]]=0;
    while(x){
        A[++A[0]]=x%10;
        x/=10;
    }
}
inline void SumMare(Huge A,Huge B,Huge &C){
    Set(C);
    int i,r=0;
    for(i=1;i<=A[0]||i<=B[0]||r;++i){
        int aux=r+A[i]+B[i];
        C[i]=aux%10;
        r=aux/10;
    }
    C[0]=i-1;
}
inline void Write(Huge A){
    for(int i=A[0];i;--i)
        printf("%d",A[i]);
    printf("\n");
}
using namespace std;
int main(){
    freopen("nunta.in","r",stdin);
    freopen("nunta.out","w",stdout);
    Huge A,B,C;
    Atrib(A,1);Atrib(B,1);
    int n;
    scanf("%d",&n);
    for(int i=2;i<=n;++i){
        SumMare(A,B,C);
        Copy(A,B);
        Copy(B,C);
    }
    Write(B);
    return 0;
}