Cod sursa(job #1004617)

Utilizator andreey_047Andrei Maxim andreey_047 Data 3 octombrie 2013 11:46:53
Problema Al k-lea termen Fibonacci Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.84 kb
#include <cstdio>

using namespace std;

    int a[100000];
int main()
{
    int i,n,ok,x,nr,aux,s,j;
        freopen("kfib.in","r",stdin);
        freopen("kfib.out","w",stdout);
            scanf("%d",&n);

    a[1] = 1; a[2] = 1;
        ok = 1;
    for(i = 3; i<=n ;i++)
    {   nr = 0;
        x = a[i-2] + a[i-1];
        aux = x;
            while(x)
            {
                nr++;
                x/=10;
            }
        x = aux;
    if(nr > 1)
        {
         s = 1;
            for(j = 1;j<nr;j++) s*=10;

            for(j = 1;j<=nr;j++)
            {
                a[i] = (x / s)%10;
               // a[i]%=666013;
                s/=10;
                i++;
            }
        }
    else
      a[i] = a[i-2]+a[i-1];


    }
        for(i = 1;i<=n;i++) printf("%d ",a[i]);
    return 0;
}