题意:输入两个数a,b,有若干个阻值为1欧姆的电阻,通过串联和并联的方式形成一个阻值为a/b的电阻
链接:http://codeforces.com/problemset/problem/343/A
思路:辗转相除累计求和
注意点:无
以下为AC代码:
# | Author | Problem | Lang | Verdict | Time | Memory | Sent | Judged |
---|---|---|---|---|---|---|---|---|
9732207 | Practice: luminous11 | 343A - 28 | GNU C++11 | Accepted | 30 ms | 4 KB | 2015-02-06 02:25:54 | 2015-02-06 02:25:54 |
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <deque>
#include <list>
#include <cctype>
#include <algorithm>
#include <climits>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#define ll long long
#define ull unsigned long long
#define all(x) (x).begin(), (x).end()
#define clr(a, v) memset( a , v , sizeof(a) )
#define pb push_back
#define mp make_pair
#define read(f) freopen(f, "r", stdin)
#define write(f) freopen(f, "w", stdout)
using namespace std;
const double pi = acos(-1);
ll calc ( ll m, ll n )
{
if ( n == 0 )return 0;
return m / n + calc ( n, m % n );
}
int main()
{
ios::sync_with_stdio( false );
ll m, n;
while ( cin >> m >> n ){
ll ans = calc ( m, n );
cout << ans << endl;
}
return 0;
}