letisen's blog

By letisen, 10 years ago, In English

this is my code. i can't find the way to optimize it.

#include <iostream>

using namespace std;

signed long long int x,y,m;
signed long long int aux=0,t=1;


signed long long int toPerfect(signed long long int a,signed long long int b,signed long    long int per){

  if(a<0){
       while( a+t*b <= 0){
              t++;           
       } 
  }else if(b<0){
        while( b+t*a <= 0){
               t++;
        } 
    }

     while(a < per && b < per){
           if(a>b){
                   b = a+b;
               }else{
                 a = a+b;
                  }
           aux++;        
      }


      if( t != 1 ){
         aux = aux + t;


    }

   return aux;
}

 int main(){
   cin >>x>>y>>m;
    cout << toPerfect(x,y,m) << endl;

 }

Full text and comments »

  • Vote: I like it
  • -5
  • Vote: I do not like it