#include<stdio.h>

//we have defined the necessary header files here for this problem.
//If additional header files are needed in your program, please import here. /* * 函数int deal(int n,int m):处理达到(n,m)转化为(1,1)时需要的次数
首先保证n<=m
当n==1时,deal(1,m)应该返回 m-1 (规律)
当n不为1且n==m时、或当n < 1时,无法转化到(1,1) 返回无效值-1
将deal(n,m)转化为deal(n,m%n),这里在n远远小于m时,远远比用减号要快,也不会Stackoverflow
如果deal(n,m%n)返回有效值,就把m/n这个转化次数加上返回
函数 resolve(n):对n进行从(1,n-1)(2,n-2)…(n/2,n-n/2)进行遍历调用
如果返回了合法值,就和min比较替换
返回时注意要加上首次拆开时的1次 */ int deal(int n,int m);
int resolve(int n); int main(){
int n;
while(scanf("%d",&n)!=EOF){
if(n==){
printf("%d\n",);
}else{
printf("%d\n",resolve(n));
} }
return ;
} int deal(int n,int m){
int t = ;
if(n>m){
t=m;
m=n;
n=t;
} if(n==){
return m-;
} if((n==m && n!=) || n<){
return -;
} int changeTimes = m/n;
int d = deal(n,m%n);
if(d!=-){
return changeTimes+d;
} return -;
} int resolve(int n){
int min = ;
if(n<=){
return ;
} for (int i = ; i <= n/; i++)
{
int temp = -;
temp = deal(i,n-i);
if( (temp>=) && (temp<min) ){
min = temp;
}
}
return min+;
}
题目描述

Let's assume that we have a pair of numbers (a,b). We can get a new pair (a+b,b) or (a,a+b) from the given pair in a single step.

Let the initial pair of numbers be (1,1). Your task is to find number k, that is, the least number of steps needed to transform (1,1) into the pair where at least one number equals n.

解答要求时间限制:1000ms, 内存限制:64MB
输入

The input contains the only integer n (1 ≤ n ≤ 106).Process to the end of file.

输出

Print the only integer k.

最新文章

  1. [函數] Firemonkey Android 取得系统参数设定的字型大小
  2. 1334: [Baltic2008]Elect
  3. Lwip的相关资料
  4. asp.net 文件压缩zip下载
  5. 多维数组遍历PHP
  6. centOS下调整swap
  7. ord()与char()
  8. dokcer自动化构建部署java web 基于jenkins+maven+nuxus容器
  9. Python学习--Python变量类型
  10. 后台执行Bitmap加载
  11. Java 中的“implements Runnable” 和“extends Thread”(转)
  12. WPF如何为程序添加splashScreen(初始屏幕)
  13. bzoj2817[ZJOI2012]波浪
  14. [Java学习] Java类的基本运行顺序
  15. .Net实现表达式计算(公式) 表达式字符串
  16. NGINX:sticky模块实现基于cookie的负载均衡
  17. javscript踩过的坑 - 记录
  18. poj 1284 Primitive Roots(未完)
  19. 转:libFuzzer Tutorial(libFuzzer教程)
  20. Thrift之c++实例

热门文章

  1. springboot2.0入门(一)----springboot 简介
  2. CSS网站收藏
  3. is(expr|obj|ele|fn)
  4. IVIEW组件的render方法在Table组件中的使用
  5. SpringMVC——参数传递
  6. MySQL之pymysql
  7. springboot批量读取参数映射到实体类
  8. dubbo服务provider方打印警告日志,getDeserializer - Hessian/Burla &#39;xxx&#39; is an unknown class
  9. js获取后台传给前台的值
  10. easyUI之Tree(树)