Subscribe Us

Responsive Advertisement

Advertisement

URI Online Judge | 1739 Threebonacci Sequence solution in cpp

 

uri 1739 solution in cpp

by ujjal roy




#include<bits/stdc++.h>

using namespace std;

int dv(long long int x)

{

    while(x>0)

    {

        if(x%10==3)

        {

            return 1;

        }

        x=x/10;

    }

    return 0;


}

main()

{


    int n,i;

    while(cin>>n)

    {

        long long int a[1500];

        int c=0;

        a[0]=0;

        a[1]=1;

        for(i=2;i<1400;i++)

        {

            a[i]=a[i-2]+a[i-1];


        }

         for(i=2;i<1400;i++)

        {

           if(a[i]%3==0||dv(a[i])==1)

           {

               c++;

           }

           if(c==n) break;


        }


        cout<<a[i]<<endl;


    }



    return 0;

}


Post a Comment

0 Comments