-
Notifications
You must be signed in to change notification settings - Fork 0
/
A.cpp
51 lines (49 loc) · 898 Bytes
/
A.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0);cin.tie(0)
int main()
{
fastio;
long long a,b,m,i,cnt=0,ara[5];
cin>>a>>b>>m;
if(max(a,b)>=m)
{
cout<<0<<"\n";
return 0;
}
if(max(a,b)<=0)
{
cout<<-1<<"\n";
return 0;
}
if(min(a,b)<0)
{
if(((-1)*min(a,b))%max(a,b)==0)
cnt=((-1)*min(a,b))/max(a,b);
else
cnt=1+((-1)*min(a,b))/max(a,b);
if(a==min(a,b))
a+=cnt*b;
else
b+=cnt*a;
}
ara[0]=min(a,b);
ara[1]=max(a,b);
if(ara[1]>=m)
{
cout<<cnt<<"\n";
return 0;
}
for(i=0;;i++)
{
ara[0]=ara[0]+ara[1];
cnt++;
if(ara[0]>=m)
{
cout<<cnt<<"\n";
break;
}
swap(ara[0],ara[1]);
}
return 0;
}