Cod sursa(job #1004813)

Utilizator andreey_047Andrei Maxim andreey_047 Data 3 octombrie 2013 18:01:29
Problema Al k-lea termen Fibonacci Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include <cstdio>
#define m 666013

using namespace std;

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

    a[1] = 1; a[2] = 1;
    t[1] = 1; t[2] = 1;
    k = 3;
        ok = 1;
    for(i = 3; i<=n ;i++)
    {
        x = a[i-2] + a[i-1];

        // nr
        aux = x;
        nr = 0;
            while(x)
            {
                nr++;
                x/=10;
            }
        x = aux;
        // done

    if(nr > 1)
        {
         s = 1;
            for(j = 1;j<nr;j++) s*=10;

            for(j = 1;j<=nr;j++)
            {
                t[k] = ((x / s)%10)%m;
                k++;
               // a[i]%=666013;
                s/=10;

            }
        }
    else
      {t[k] = x%m; k++;}

        a[i] = x;
    }

        printf("%d\n",t[k-1]);
    return 0;
}