日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces Round #200 (Div. 1)A. Rational Resistance 数学

發布時間:2025/5/22 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces Round #200 (Div. 1)A. Rational Resistance 数学 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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:

  • one resistor;
  • an element and one resistor plugged in sequence;
  • 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 = 0;while(a&&b){ans += a/b;a%=b;swap(a,b);}printf("%lld\n",ans); }

    ?

    轉載于:https://www.cnblogs.com/qscqesze/p/4870943.html

    總結

    以上是生活随笔為你收集整理的Codeforces Round #200 (Div. 1)A. Rational Resistance 数学的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。