Cod sursa(job #1004831)

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


using namespace std;

    int a[1000000],t[100000000];

    int Nrcif(int x)
        {       int aux,nr;
        aux = x;
        nr = 0;
            while(x)
            {
                nr++;
                x/=10;
            }
        x = aux;
            return nr;
        }
int main()
{
    int i,n,nr,aux,s,j,k,m;
    long long x;
        freopen("kfib.in","r",stdin);

            scanf("%d",&n);
     m=666013;
    a[1] = 1; a[2] = 1;
    t[1] = 1; t[2] = 1;
    k = 3;
         n=n%(m*2+2);
    for(i = 3; i<=n;)
    {
        x = a[i-2] + a[i-1];
    nr = Nrcif(x);
    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;
        i+=nr;
    }

     freopen("kfib.out","w",stdout);
    // for(i = 1;i<k;i++)
        printf("%d ",t[k-1]);
    return 0;
}