B. Strings of Power

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/318/problem/C

Description

Let us call a pair of integer numbers m-perfect, if at least one number in the pair is greater than or equal to m. Thus, the pairs (3, 3) and (0, 2) are 2-perfect while the pair (-1, 1) is not.

Two integers x, y are written on the blackboard. It is allowed to erase one of them and replace it with the sum of the numbers, (x + y).

What is the minimum number of such operations one has to perform in order to make the given pair of integers m-perfect?

Input

Single line of the input contains three integers x, y and m ( - 1018 ≤ x, y, m ≤ 1018).

Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preffered to use the cin, cout streams or the %I64d specifier.

Output

Print the minimum number of operations or "-1" (without quotes), if it is impossible to transform the given pair to the m-perfect one.

Sample Input

1 2 5

Sample Output

2

HINT

题意

给你x,y,每次你可以选择一个数,让他变成x+y,然后问最少多少步,可以使得x,y中的最大值大于等于k

题解:

这道题类似于fib数,所以我们只要把(x,y)变成(y,x+y)就好

注意,全程爆ll

代码:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 4000001
#define mod 10007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** int main()
{
ll x=read(),y=read(),k=read();
if(x>=k||y>=k)
{
cout<<""<<endl;
return ;
}
if(x<k&&y<k&&x<=&&y<=)
{
cout<<"-1"<<endl;
return ;
}
ll ans=;
if(x>y)
swap(x,y);
if(x<)
{
ans=(y-x)/y;
x+=ans*y;
}
while(y<k)
{
ll tmp=x;
x=y;
y=tmp+y;
ans++;
}
cout<<ans<<endl;
}

Codeforces Round #188 (Div. 2) C. Perfect Pair 数学的更多相关文章

  1. Codeforces Round #188 (Div. 1 + Div. 2)

    A. Even Odds 奇数个数\(\lfloor \frac{n+1}{2}\rfloor\) B. Strings of Power 从位置0开始,统计heavy个数,若当前为metal,则可以 ...

  2. Codeforces Round #460 (Div. 2) B Perfect Number(二分+数位dp)

    题目传送门 B. Perfect Number time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  3. Codeforces Round #188 (Div. 1) B. Ants 暴力

    B. Ants Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/317/problem/B Des ...

  4. Codeforces Round #188 (Div. 2) B. Strings of Power 水题

    B. Strings of Power Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/p ...

  5. Codeforces Round #188 (Div. 2) A. Even Odds 水题

    A. Even Odds Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/problem/ ...

  6. Codeforces Round #462 (Div. 2) A Compatible Pair

    A. A Compatible Pair time limit per test1 second memory limit per test256 megabytes Problem Descript ...

  7. Codeforces Round #460 (Div. 2)-B. Perfect Number

    B. Perfect Number time limit per test2 seconds memory limit per test256 megabytes Problem Descriptio ...

  8. 【博弈论】【SG函数】Codeforces Round #188 (Div. 1) D. Game with Powers

    将整个游戏可以划分成若干个互不相交的子游戏. 每个子游戏的sg值只与其中的数的个数有关.而这个数不会超过30. 于是可以预处理出这个sg值表. 然后从1到n枚举,对<=sqrt(n)的部分,用个 ...

  9. Codeforces Round #274 (Div. 1) B. Long Jumps 数学

    B. Long Jumps Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/ ...

随机推荐

  1. UIButton 在UIScrollView里面 点击效果不明显的问题

    self.scrollView.delaysContentTouches = NO; -(BOOL)touchesShouldCancelInContentView { return YES; }

  2. seo技巧-2015/10/05

    1.每页都要有它自己的文件名,并且有它自己的上级文件夹和它自己相关关键字. 2.建议在每页上使用一个的H1标签.我也试着使用许多H2 或H3的标签在页面内辅助构成正文内容. 3. 有时花费一点钱帮助你 ...

  3. VHDL之Port map and open

    编SPI的master控制器,使用公司基本的元件,有些端口用不着,恰巧好二哥(不知年龄的数字组组长,本名Holger)来了,于是请教之,告曰open关键词.后来深感自己VHDL水平太水,下了一本电子书 ...

  4. Context3D 不可用

    打开项目文件夹中的html-template,并找到index.template.html,右键使用TextEditor编辑,在params.allowfullscreen=”true”:后面加上pa ...

  5. incompatible

  6. C++11无限制的unions

    [C++11无限制的unions] 在标准 C++ 中,并非任意的类型都能做为 union 的成员.比方说,带有 non-trivial 构造函数的类型就不能是 union 的成员.在新的标准里,移除 ...

  7. DELPHI7在WIN8和WIN10下安装和运行

    DELPHI7在WIN8下安装后可以打开运行,但发现设置断点DEBUG运行DLL工程时会卡死(IDE长时间无反应,不报错). DELPHI7在WIN10下安装后打开的时候会报错,无法运行. 以上两种情 ...

  8. css div 垂直居中

    参考:http://css-tricks.com/centering-in-the-unknown/ <style> .valign { font-size: 0px;/* clear s ...

  9. ASP.NET MVC- DropDownList绑定

    看一下Controller例子 [ChildActionOnly] public List<SelectListItem> LoadItemStatus() { List<Selec ...

  10. 一个人写的操作系统 - Sparrow OS

    一个人写的操作系统 - Sparrow OS 自己写一个操作系统,这是在过去的几年里我一直为之努力的目标,现在终于完成了. 缘起 自己动手写操作系统的动机最初来自于学习Linux遇到的困难. 我是一个 ...