http://codeforces.com/contest/318/problem/C
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 long long j; 6 long long x,y,m; 7 int main() 8 { 9 scanf("%I64d%I64d%I64d",&x,&y,&m); 10 if(x>=m||y>=m) 11 { 12 printf("0 "); 13 return 0; 14 } 15 else if(x<=0&&y<=0) 16 { 17 printf("-1 "); 18 return 0; 19 } 20 if(x<0) 21 { 22 j=(-x)/y+1; 23 x+=j*y; 24 } 25 if(y<0) 26 { 27 j=(-y)/x+1; 28 y+=j*x; 29 } 30 while(1) 31 { 32 if(!(x<m&&y<m)) break; 33 if(x>y) y=x+y; 34 else x=x+y; 35 j++; 36 } 37 printf("%I64d ",j); 38 return 0; 39 }