Skip to content

Commit 45bf0d9

Browse files
authored
Add problem statement for Resistor Time Machine
Added problem statement for 'Resistor Time Machine' including input and output specifications, examples, and a problem link.
1 parent 2cc95fa commit 45bf0d9

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,72 @@
11

2+
# Resistor Time Machine
3+
4+
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.
5+
6+
However, all Mike has is lots of identical resistors with unit resistance $$[R_0 = 1\]$$. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:
7+
8+
- one resistor;
9+
- an element and one resistor plugged in sequence;
10+
- an element and one resistor plugged in parallel.
11+
12+
With the consecutive (series) connection the resistance of the new element equals
13+
14+
\[ R = $$R_e + R_0$$. \]
15+
16+
With the parallel connection the resistance of the new element equals
17+
18+
$$\[ R = \frac{R_e \cdot R_0}{R_e + R_0}. \]$$
19+
20+
In these formulas, $$\(R_e\)$$ denotes the resistance of the element being connected.
21+
22+
Mike needs to assemble an element with a resistance equal to the fraction $$\(\dfrac{a}{b}\)$$. Determine the smallest possible number of resistors he needs to make such an element.
23+
24+
---
25+
26+
## Input
27+
28+
The single input line contains two space-separated integers $$\(a\)$$ and $$\(b\)$$ $$(\(1 \le a, b \le 10^{18}\))$$. It is guaranteed that the fraction $$\(\dfrac{a}{b}\)$$ is irreducible. It is guaranteed that a solution always exists.
29+
30+
> Please do not use the `%lld` specifier to read or write 64-bit integers in C++. It is recommended to use the `cin`, `cout` streams or the `%I64d` specifier.
31+
32+
## Output
33+
34+
Print a single number — the answer to the problem (the minimum number of unit resistors required).
35+
36+
## Examples
37+
38+
**Input**
39+
```
40+
1 1
41+
```
42+
**Output**
43+
```
44+
1
45+
```
46+
47+
**Input**
48+
```
49+
3 2
50+
```
51+
**Output**
52+
```
53+
3
54+
```
55+
56+
**Input**
57+
```
58+
199 200
59+
```
60+
**Output**
61+
```
62+
200
63+
```
64+
65+
## Note
66+
67+
In the first sample, one resistor is enough.
68+
69+
In the second sample one can connect two resistors in parallel (obtaining resistance $$\(\tfrac{1}{2}\))$$, take the resulting element and connect it to a third resistor consecutively (series), giving $$\(\tfrac{1}{2} + 1 = \tfrac{3}{2}\)$$. We cannot make this element using two resistors.
70+
71+
---
72+
[PROBLEM LINK](https://codeforces.com/contest/343/problem/A)

0 commit comments

Comments
 (0)