A. Rational Resistance

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/343/problem/A

Description

Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.

However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:

  1. one resistor;
  2. an element and one resistor plugged in sequence;
  3. an element and one resistor plugged in parallel.

With the consecutive connection the resistance of the new element equals R = Re + R0. With the parallel connection the resistance of the new element equals . In this case Re equals the resistance of the element being connected.

Mike needs to assemble an element with a resistance equal to the fraction . Determine the smallest possible number of resistors he needs to make such an element.

Input

The single input line contains two space-separated integers a and b (1 ≤ a, b ≤ 1018). It is guaranteed that the fraction is irreducible. It is guaranteed that a solution always exists.

Output

Print a single number — the answer to the problem.

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

Sample Input

199 200

Sample Output

200

HINT

题意

你有无数个1欧的电阻,要求你用并联和串联构成a/b欧的电阻

问你最少需要多少个电阻

题解:

首先结构肯定是串联加并联啦

a/b,整数部分由串联构成,分数部分由并联构成就好了

这样就可以不停的递归了其实

代码:

#include<stdio.h>
#include<math.h>
#include<iostream>
using namespace std; int main()
{
long long a,b;
scanf("%lld%lld",&a,&b);
if(a<b)swap(a,b);
long long ans = ;
while(a&&b)
{
ans += a/b;
a%=b;
swap(a,b);
}
printf("%lld\n",ans);
}

Codeforces Round #200 (Div. 1)A. Rational Resistance 数学的更多相关文章

  1. Codeforces Round #200 (Div. 2) C. Rational Resistance

    C. Rational Resistance time limit per test 1 second memory limit per test 256 megabytes input standa ...

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

    A. Magnets 模拟. B. Simple Molecules 设12.13.23边的条数,列出三个等式,解即可. C. Rational Resistance 题目每次扩展的电阻之一是1Ω的, ...

  3. Codeforces Round #200 (Div. 1)D. Water Tree dfs序

    D. Water Tree Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343/problem/ ...

  4. Codeforces Round #200 (Div. 1) C. Read Time 二分

    C. Read Time Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343/problem/C ...

  5. Codeforces Round #200 (Div. 1) B. Alternating Current 栈

    B. Alternating Current Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343 ...

  6. Codeforces Round #200 (Div. 1) BCD

    为了锻炼个人能力奋力div1 为了不做原题从200开始 B 两个电线缠在一起了 能不能抓住两头一扯就给扯分开 很明显当len为odd的时候无解 当len为偶数的时候 可以任选一段长度为even的相同字 ...

  7. Codeforces Round #200 (Div. 2)D. Alternating Current (堆栈)

    D. Alternating Current time limit per test 1 second memory limit per test 256 megabytes input standa ...

  8. Codeforces Round #200 (Div. 1) D. Water Tree(dfs序加线段树)

    思路: dfs序其实是很水的东西.  和树链剖分一样, 都是对树链的hash. 该题做法是:每次对子树全部赋值为1,对一个点赋值为0,查询子树最小值. 该题需要注意的是:当我们对一棵子树全都赋值为1的 ...

  9. Codeforces Round #200 (Div. 2) E. Read Time(二分)

    题目链接 这题,关键不是二分,而是如果在t的时间内,将n个头,刷完这m个磁盘. 看了一下题解,完全不知怎么弄.用一个指针从pre,枚举m,讨论一下.只需考虑,每一个磁盘是从右边的头,刷过来的(左边来的 ...

随机推荐

  1. uyouo[]常棒的一篇关于innnodb next-key lock的文章

    何登成的 MySQL 加锁处理分析 Innodb锁机制:Next-Key Lock 浅谈

  2. JAVA并行框架学习之ForkJoin

    当硬件处理能力不能按照摩尔定律垂直发展的时候,选择了水平发展,多核处理器已经广泛应用.未来随着技术的进一步发展,可能出现成百上千个处理核心,但现有的程序运行在多核心处理器上并不能得到较大性能的提升,主 ...

  3. -_-#【Dom Ready / Dom Load】

    Dom Ready和Dom Load DOM Ready 详解 javascript的domReady 域名解析 - 加载html - 加载js和css - Dom Ready - 加载图片等其他信息 ...

  4. UpYun上传 401 Unauthorized

    _upt=3b9b444a14059041252014-07-21 08:46:25,218 ERROR (com.UpYun:518) - Upload file error:<h1>4 ...

  5. EntityFramework程序集版本不同

    问题: Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE /* Style Definitions */ table.MsoNormalT ...

  6. .NET 4.0中的泛型协变和逆变

    随Visual Studio 2010 CTP亮相的C#4和VB10,虽然在支持语言新特性方面走了相当不一样的两条路:C#着重增加后期绑定和与动态语言相容的若干特性,VB10着重简化语言和提高抽象能力 ...

  7. c#保存datagridview中的数据时报错 “动态SQL生成失败。找不到关键信息”

    ilovejinglei 原文 C#中保存datagridview中的数据时报错"动态SQL生成失败.找不到关键信息" 问题描述     相关代码 using System; us ...

  8. 移动端混合型App(hybrid app)自动化测试选型与实践

    背景 公司产品的业务已经发展到了移动端,开发选型已经结束,决定使用phonegap做移动端的web应用开发平台.考虑到业务的复杂与多样,移动端的测试同样需要自动化.在网上看了很多,最终锁定了3个移动端 ...

  9. 文件I/O操作(1)

    linux系统调用和用户编程接口(api) 系统调用是指在操作系统提供给用户程序调用的一组“特殊”的接口,用户程序可以通过这组特殊的接口来获取操作系统内核提供的服务,例如用户可以通过进程控制相关的系统 ...

  10. PPTP VPN不能打开百度

    问题: 在阿里云上设置PPTP VPN,电脑能正常连接,能打开京东 淘宝 QQ等没有问题,但是不能打开百度  糯米等网站.开始怀疑是代理设置问题,后面确认未设置独立规则. 1.从应用层看排除特殊规则设 ...