submission_id string | problem_id string | status string | code string | input string | output string | problem_description string |
|---|---|---|---|---|---|---|
s867439284 | p04048 | Runtime Error | from math import gcd
n, x = map(int, input().split())
print(3 * (n - gcd(n, x)))
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s876123929 | p04048 | Runtime Error | from math import gcd
n, x = map(int, input().split())
print(3*(n-gcd(n, x)))
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s257332778 | p04048 | Runtime Error | N = int(input())
X = int(input())
Total_Length = 2*X + N + 3*(X//2)
print(Total_Length) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s298220524 | p04048 | Runtime Error | def run():
N, X = map(int, input().split())
y = N-X
ans = y+X
while True:
a = y//X
ans += a*X*2
if y%X == 0:
break
y, X = max(X, a), min(X, a)
print(ans-X)
if __name__ == '__main__':
run() | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s438951925 | p04048 | Runtime Error | def run():
N, X = map(int, input().split())
y = N-X
ans = y+X
while True:
a = y//X
ans += a*X*2
if y%X == 0:
break
y, X = X, a
print(ans-X)
if __name__ == '__main__':
run() | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s108536014 | p04048 | Runtime Error | import sys
import math
sys.setrecursionlimit(1000)
def f(x, y):
if y < x:
(y, x) = (x, y)
if x == 0:
return y
return x + y + f(x, y - x)
n, x = map(int, input().split())
print(x + f(x, n - x) - math.gcd(n, x)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s821995801 | p04048 | Runtime Error | import sys
sys.setrecursionlimit(1000)
def f(x, y):
if y < x:
(y, x) = (x, y)
if x == 0:
return y
return x + y + f(x, y - x)
n, x = map(int, input().split())
print(x + f(x, n - x) - 1)
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s564518548 | p04048 | Runtime Error | def f(x, y):
if y < x:
(y, x) = (x, y)
if x == 0:
return y
return x + y + f(x, y - x)
n, x = map(int, input().split())
print(x + f(x, n - x) - 1) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s738614827 | p04048 | Runtime Error | def f(x, y):
if y < x:
y, x = x, y
if y == 0:
return x
return x + y + f(x, y - x)
n, x = map(int, input().split())
print(x + f(x, n - x)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s753370104 | p04048 | Runtime Error | import math
n, x = map(int, input().split())
print(n * x // math.gcd(n, x) + x)
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s635919951 | p04048 | Runtime Error | import math
n, x = map(int, input().split())
print(n * x / math.gcd(n, x) + x) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s871397787 | p04048 | Runtime Error | # -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
N, X = MAP()
def rec(a, b):
if a == b:
return a
a, b = min(a, b), max(a, b)
return a*2 + rec(a, b-a)
print(N+rec(X, N-X))
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s015771046 | p04048 | Runtime Error | # -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
N, X = MAP()
if N%2 == 1:
print((N-1)*3)
else:
raise Exception
print(N*3//2+abs(X-N//2)*3)
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s486035428 | p04048 | Runtime Error | n, x = map(int, input().split())
if (n%2 == 1):
print((n-1)*3)
elif (n==2):
print(3)
else:
k=n/2
if (x<k):
if((n/2)%2==0):
l = []
for i in range(1,k-2):
l.append(((n-1)*3)-3*(x-1))
last = l[0]
l.append(last)
print(l[x-1])
else:
if (x%2==0):
print((n-2)*3)
else:
print((n-1)*3)
elif(x==k):
print(int(k*3))
else:
p = n-x
if (p<k):
if((n/2)%2==0):
l = []
for i in range(1,k-2):
l.append(((n-1)*3)-3*(p-1))
last = l[0]
l.append(last)
print(l[p-1])
else:
if (p%2==0):
print((n-2)*3)
else:
print((n-1)*3)
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s163593323 | p04048 | Runtime Error | import sys
sys.setrecursionlimit(10 ** 9)
N, X = map(int, input().split())
def f(a, b):
if a == b:
return a
if a >= b:
a, b = b, a
if b%a != 0:
return 2 * a * (b//a) + f(a, b%a)
return 2 * a + f(a, b - a)
print (N + f(N - X, X)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s970175330 | p04048 | Runtime Error | import sys
sys.setrecursionlimit(10 ** 9)
N, X = map(int, input().split())
def f(a, b):
if a == b:
return a
if a >= b:
a, b = b, a
return 2 * a + f(a, b - a)
print (N + f(N - X, X)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s798673727 | p04048 | Runtime Error | N, X = map(int, input().split())
def f(a, b):
if a == b:
return a
if a >= b:
a, b = b, a
return 2 * a + f(a, b - a)
print (N + f(N - X, X)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s438101089 | p04048 | Runtime Error | #座標平面に落とし込んで再帰関数で無理やり計算
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5)
N, X = map(int, input().split())
if 2 * X > N: #対称性
X = N - X
#座標の作成
dp = [[-1] * (N+3)]
for i in range(N+1):
tmp = [-1]
for j in range(N+1):
if i <= j:
tmp.append(0) #到達していないマス
else:
tmp.append(-1) #壁(範囲外)
tmp.append(-1)
tmp.reverse()
dp.append(tmp)
dp.append([-1] * (N+3))
# print (np.array(dp))
#m: 0:右へ, 1:左下へ, 2:左上へ
def moving(x, y, total, m):
if x == X and y == 1 and dp[x][y] == 1: #一周回ってもとの座標に戻ってきた時
# print ('D')
return total
if m == 0: #右に動く時
tmp = 0
while dp[x-1][y+1] == 0: #右に進める時
dp[x-1][y+1] = 1 #右進んだマスを到達したことにする
tmp += 1
x -= 1
y += 1
if dp[x-1][y+1] == -1: #右側が壁の時-->左下に進む
# print ('1-B')
return moving(x, y, total + tmp, 1)
if dp[x-1][y+1] == 1: #右側が光の線の時-->左上へ進む
tmp += 1
# print ('1-C')
return moving(x-1, y+1, total + tmp, 2)
if m == 1: #左下へ動く時
tmp = 0
while dp[x+1][y] == 0: #左下に進める時
dp[x+1][y] = 1
tmp += 1
x += 1
if dp[x+1][y] == -1: #左下が壁の時-->左上に進む
# print ('2-C')
return moving(x, y, total + tmp, 2)
if dp[x+1][y] == 1: #左下が光の線の時-->左上に進む
tmp += 1
# print ('2-C')
return moving(x+1, y, total + tmp, 2)
if m == 2: #左上に動く時
tmp = 0
while dp[x][y-1] == 0: #左上に進める時
dp[x][y-1] = 1
tmp += 1
y -= 1
if dp[x][y-1] == -1: #左上が壁の時-->右に進む
# print ('3-A')
return moving(x, y, total + tmp, 0)
if dp[x][y-1] == 1: #左上が光の線の時-->左下に進む
tmp += 1
# print ('3-B')
return moving(x, y-1, total + tmp, 1)
X += 1
print (moving(X, 1, 0, 0))
# print (np.array(dp)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s836050967 | p04048 | Runtime Error | # import numpy as np
# import sys
# sys.setrecursionlimit(100)
N, X = map(int, input().split())
if N > 1000:
exit()
if 2 * X > N:
X = N - X
#座標の作成
dp = [[-1] * (N+3)]
for i in range(N+1):
tmp = [-1]
for j in range(N+1):
if i <= j:
tmp.append(0) #到達していないマス
else:
tmp.append(-1) #壁(範囲外)
tmp.append(-1)
tmp.reverse()
dp.append(tmp)
dp.append([-1] * (N+3))
# print (np.array(dp))
#m: 0:右へ, 1:左下へ, 2:左上へ
def moving(x, y, total, m):
if x == X and y == 1 and dp[x][y] == 1:
# print ('D')
return total
if m == 0: #右に動く時
tmp = 0
while dp[x-1][y+1] == 0: #右に進める時
dp[x-1][y+1] = 1 #右進んだマスを到達したことにする
tmp += 1
x -= 1
y += 1
if dp[x-1][y+1] == -1: #右側が壁の時-->左下に進む
# print ('1-B')
return moving(x, y, total + tmp, 1)
if dp[x-1][y+1] == 1: #右側が光の線の時-->左上へ進む
tmp += 1
# print ('1-C')
return moving(x-1, y+1, total + tmp, 2)
if m == 1: #左下へ動く時
tmp = 0
while dp[x+1][y] == 0: #左下に進める時
dp[x+1][y] = 1
tmp += 1
x += 1
if dp[x+1][y] == -1: #左下が壁の時-->左上に進む
# print ('2-C')
return moving(x, y, total + tmp, 2)
if dp[x+1][y] == 1: #左下が光の線の時-->左上に進む
tmp += 1
# print ('2-C')
return moving(x+1, y, total + tmp, 2)
if m == 2: #左上に動く時
tmp = 0
while dp[x][y-1] == 0: #左上に進める時
dp[x][y-1] = 1
tmp += 1
y -= 1
if dp[x][y-1] == -1: #左上が壁の時-->右に進む
# print ('3-A')
return moving(x, y, total + tmp, 0)
if dp[x][y-1] == 1: #左上が光の線の時-->左下に進む
tmp += 1
# print ('3-B')
return moving(x, y-1, total + tmp, 1)
X += 1
print (moving(X, 1, 0, 0))
# print (np.array(dp)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s223030371 | p04048 | Runtime Error | N,X = map(int, input().split())
def para(a,b):
if a == b:
return a
if a > b:
return 2*b + para(b,a-b)
if a < b:
return 2*a + para(a,b-a)
print(N+para(X,N-X)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s736998737 | p04048 | Runtime Error | N,X = map(int, input().split())
def para(a,b):
if b == 0:
return a
if a >= b:
return a+b + para(b,a-b)
if a < b:
return 2*a + para(a,b-a)
print(X+para(X,N-X)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s761842807 | p04048 | Runtime Error | N,X = map(int, input().split())
def para(a,b):
if a > b:
return a+b + para(b,a-b)
if a < b:
return 2*a + para(a,b-a)
if a == b:
return 3*a
print(X+para(X,N-X)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s296000499 | p04048 | Runtime Error | N,X = map(int, input().split())
print(N)
print(X)
def para(a,b):
if a > b:
return a+b + para(b,a-b)
if a < b:
return 2*a + para(a,b-a)
if a == b:
return 3*a
print(X+para(X,N-X)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s248720864 | p04048 | Runtime Error | N,X = map(int, input().split())
print(N)
print(X)
def para(a,b):
if a > b:
return 2*b + para(b,a-b)
if a < b:
return 2*a + para(b-a,a)
if a == b:
return a
print(N+para(X,N-X)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s663748375 | p04048 | Runtime Error | n,x=map(int,input().split())
ans=0
if x<n/2:
a=x
b=n-x
ans+=x+n
while True:
if b%a==0:
ans+=a*2*(b/a)
break
else:
ans+=a*2*(b//a)
a,b=b%a,a
elif x=n/2:
ans=3*x
elif x>n/2:
a=n-x
b=x
ans+=x
while True:
if b%a==0:
ans+=a*2*(b/a)
break
else:
ans+=a*2*(b//a)
a,b=b%a,a
print(ans)
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s171165520 | p04048 | Runtime Error | n,x=map(int,input().split())
ans=0
if x<n/2:
a=x
b=n-x
ans+=x+n
while True:
if b%a=0:
ans+=a*2*(b/a)
break
else:
ans+=a*2*(b//a)
a,b=b%a,a
elif x=n/2:
ans=3*x
elif x>n/2:
a=n-x
b=x
ans+=x
while True:
if b%a=0:
ans+=a*2*(b/a)
break
else:
ans+=a*2*(b//a)
a,b=b%a,a
print(ans)
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s824369964 | p04048 | Runtime Error | N,X = map(int, input().split())
if N/2 == X:
print(X*3)
elif N/2 > X:
# 上側
l = X + N - X
l += ((N-X)//X)*2
n = (N-X)%X
l += (X//n)*2*n
l += n
else:
l = X
n = X-N
l += (N//n)*2*n
print(l) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s696173132 | p04048 | Runtime Error | N,X = map(int, input().split())
if N/2 == X:
print(X*3)
else:
# 上側
l = X + N - X
while X > 0:
l += X*2
X -= 1
l += 1
print(l) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s934838862 | p04048 | Runtime Error | n,m=map(int,input().split())
print(n//2*3if n//2=m else n*3-3) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s717233358 | p04048 | Runtime Error | n, x = [int(i) for i in input().split()]
cnt=0
short = n%x
long = x
cnt += x*(2*(n//x)-1) + (n-x)
while(1):
c = long % short
a = long //short
if c==0:
break
else:
cnt += short * 2 * a
long = short
short = c
cnt += short * 2 * a -1
print(cnt)
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s319909280 | p04048 | Runtime Error | def f(a,b):
if a==b:
ret = a
elif a < b:
ret = 2*a + f(a,b-a)
else:
ret = 2*b + f(a-b,b)
return ret
N,X = map(int,input().split(" "))
print(N+f(N-X,X))
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s744545686 | p04048 | Runtime Error | def f(a,b):
if a==b:
return 2*a
elif a < b:
return 2*a + f(a,b-a)
else:
return 2*b + f(a-b,b)
N,X = map(int,input().split(" "))
print(N+f(N-X,X)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s527203596 | p04048 | Runtime Error | def f(a,b):
return 2*a + f_fast(a,b-a)
def f_fast(a,b):
if a==b:
return a+b
elif a < b:
if b%a == 0:
return f(a,b)
else:
d = b//a
return 2*a*d + f_fast(a,b%a)
else:
return f_fast(b,a)
N,X = map(int,input().split(" "))
print(N+f_fast(N-X,X)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s861657137 | p04048 | Runtime Error | def f(a,b):
print(a,b)
if a==b:
return 2*a
elif a < b:
return 2*a + f(a,b-a)
else:
return 2*b + f(a-b,b)
N,X = map(int,input().split(" "))
print(N+f(N-X,X)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s158402728 | p04048 | Runtime Error | n,x = map(int,input().split())
def f(a,b):
if a == b:
return a
elif a < b:
return 2*a + f(a,b-a)
else:
return 2*b + f(b,a-b)
print(n+f(x,n-x)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s384630814 | p04048 | Runtime Error | n,x = map(int,input().split())
def f(a,b):
if a == b:
return a
elif a < b:
return 2*a + f(a,b-a)
else:
return 2*b + f(a-b,b)
print(n+f(x,n-x)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s175677841 | p04048 | Runtime Error | def solve(s, a, b):
if a % b == 0:
return s + ((a // b) * 2 - 1) * b
if b % a == 0:
return s + ((b // a) * 2 - 1) * a
if a == b:
return s + a
elif a > b:
return solve(s + b * 2, a - b, b)
else:
return solve(s + a * 2, a, b - a)
n, x = map(int, input().split())
print(solve(n, n - x, x)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s288708942 | p04048 | Runtime Error | def solve(s, a, b):
if a == 1:
return s + b * 2 - 1
if b == 1:
return s + a * 2 - 1
if a == b:
return s + a
elif a > b:
return solve(s + b * 2, a - b, b)
else:
return solve(s + a * 2, a, b - a)
n, x = map(int, input().split())
print(solve(n, n - x, x)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s798109564 | p04048 | Runtime Error | import sys
sys.setrecursionlimit(100000000)
def solve(s, a, b):
if a == b:
return s + a
elif a > b:
return solve(s + b * 2, a - b, b)
else:
return solve(s + a * 2, a, b - a)
n, x = map(int, input().split())
print(solve(0, n - x, x) + n) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s144935227 | p04048 | Runtime Error | def solve(s, a, b):
if a == b:
return s + a
elif a > b:
return solve(s + b * 2, a - b, b)
else:
return solve(s + a * 2, a, b - a)
n, x = map(int, input().split())
print(solve(0, n - x, x) + n) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s834018018 | p04048 | Runtime Error | N, X = map(int, input().split())
l = N//X
q = N%X
print(N + 2*(l-1)*X + q*((X//q) + 1)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s294232485 | p04048 | Runtime Error | N, X = map(int, input().split())
l = N//X
q = N%X
print(N + 2*(l-1)*X + q*(X//q + 1)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s345405098 | p04048 | Runtime Error | #-*-coding: utf-8-*-
N, X = map(int, input().split())
l = N//X
q = N%X
print(N + 2*(l-1)*X + q*(X//q + 1)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s737283365 | p04048 | Runtime Error | #-*-coding: utf-8-*-
N, X = map(int, input().split())
print(N + 2*((N//X)-1)*X + (N%X) * (X//(X//(N%X)) + 1)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s099015926 | p04048 | Runtime Error | #-*-coding: utf-8-*-
N, X = map(int, input().split())
print(N + 2*((N//X)-1)*X + (N%X) * (X//(X//(N%X)) + 1)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s432698194 | p04048 | Runtime Error | #-*-coding: utf-8-*-
N, X = map(int, input().split())
print(N + 2*((N//X)-1)*X + (N%X) * (X//(X//q) + 1)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s936674618 | p04048 | Runtime Error | import fraction
li = [int(i) for i in input().split(" ")]
res = (li[0] // fraction.gcd(li[0], li[1]) -1) * 3 * fraction.gcd(li[0], li[1])
print(res) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s782042100 | p04048 | Runtime Error | import math
li = [int(i) for i in input().split(" ")]
res = (li[0] // math.gcd(li[0], li[1]) -1) * 3 * math.gcd(li[0], li[1])
print(res) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s091075627 | p04048 | Runtime Error | from fractions
n,x=map(int,input().split())
print(3*(n-fractions.gcd(n,x)))
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s263588101 | p04048 | Runtime Error | import math
n,x=map(int,input().split())
print(3*(n-math.gcd(n,x)))
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s025454084 | p04048 | Runtime Error | import math
n,x=map(int,input().split())
print(4*(n-math.gcd(n,x))) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s060716523 | p04048 | Runtime Error | import math
n,x=map(int,input().split())
print(4*(n-gcd(n,x)))
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s571418060 | p04048 | Runtime Error | import sys
sys.setrecursionlimit(10**9)
N,X = map(int,input().split())
def f(a,b) :
if a < b :
return 2*a + f(a,b-a)
elif a > b :
return 2*b + f(b,a-b)
else :
return a
ans = N + f(X,N-X)
print(ans)
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s883872348 | p04048 | Runtime Error | import sys
sys.setrecursionlimit(10**12+1)
N,X = map(int,input().split())
def f(a,b) :
if a < b :
return 2*a + f(a,b-a)
elif a > b :
a,b = b,a
return 2*a + f(a,b-a)
else :
return a
ans = N + f(X,N-X)
print(ans)
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s493323134 | p04048 | Runtime Error | import sys
sys.setrecursionlimit(10**9)
N,X = map(int,input().split())
def f(a,b) :
if a < b :
return 2*a + f(a,b-a)
elif a > b :
a,b = b,a
return 2*a + f(a,b-a)
else :
return a
ans = N + f(X,N-X)
print(ans)
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s422223228 | p04048 | Runtime Error | N,X = map(int,input().split())
def f(a,b) :
if a < b :
return 2*a + f(a,b-a)
elif a > b :
a,b = b,a
return 2*a + f(a,b-a)
else :
return a
ans = N + f(X,N-X)
print(ans)
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s588470967 | p04048 | Runtime Error | N,X = map(int,input().split())
def f(a,b) :
if a < b :
return 2*a + f(a,b-a)
elif b == 0 :
return 0
else :
return ((a//b)*2-1)*b
ans = N + f(X,N-X)
print(ans)
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s797127141 | p04048 | Runtime Error | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**8)
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
def rec(a: int, b: int) -> int:
if a == b:
return a
else:
mx = max(a,b)
mn = min(a,b)
return 2*mn + rec(mn, mx-mn)
n,x = li()
print(n + rec(x, n-x))
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s844708469 | p04048 | Runtime Error | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
def rec(a: int, b: int) -> int:
if a == b:
return a
else:
mx = max(a,b)
mn = min(a,b)
return 2*mn + rec(mn, mx-mn)
n,x = li()
print(n + rec(x, n-x))
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s265781339 | p04048 | Runtime Error | def tri_len(x,y):
if x== y:
return x
elif x < y:
return tri_len(y-x,x)+2*x
else:
return tri_len(x-y,y)+2*y
import sys
sys.setrecursionlimit(100000)
n,x= list(map(int,input().split(" ")))
print( n+tri_len(x,n-x)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s352575624 | p04048 | Runtime Error | def tri_len(x,y):
if x== y:
return x
elif x < y:
return tri_len(y-x,x)+2*x
else:
return tri_len(x-y,y)+2*y
import sys
sys.setrecursionlimit(10000)
n,x= list(map(int,input().split(" ")))
print( n+tri_len(x,n-x)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s589582202 | p04048 | Runtime Error | def tri_len(x,y):
if x== y:
return x
elif x < y:
return tri_len(y-x,x)+2*x
else:
return tri_len(x-y,y)+2*y
n,x= list(map(int,input().split(" ")))
print( n+tri_len(x,n-x)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s882265313 | p04048 | Runtime Error | N = int(input())
L = list(map(int, input().split()))
L.sort()
x = 0
for i in range(0, 2*N, 2):
print(L[i])
x += L[i]
print(x) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s623476061 | p04048 | Runtime Error | import sys
N = int(sys.argv[1])
X = int(sys.argv[2])
rect = [ X, N-X ]
rect_temp = rect
length = 0
while True :
if rect_temp[0] < rect_temp[1]:
length += rect_temp[0]*3
rect_temp = [ rect_temp[0], rect_temp[1]-rect_temp[0] ]
elif rect_temp[0] > rect_temp[1]:
length += rect_temp[1]*3
rect_temp = [ rect_temp[0] - rect_temp[1], rect_temp[0] ]
elif rect_temp[0] == rect_temp[1]:
break
print(length) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s891845339 | p04048 | Runtime Error | import sys
sys.setrecursionlimit(10**15)
def f(a,b):
if a==b:return a
if not a<b:a,b=b,a
return f(a,b-a)+2*a
N,X=map(int,input().split())
print(f(X,N-X)+N)
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s286661045 | p04048 | Runtime Error | import sys
sys.setrecursionlimit(10**7)
def f(a,b):
if a==b:return a
if not a<b:a,b=b,a
return f(a,b-a)+2*a
N,X=map(int,input().split())
print(f(X,N-X)+N) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s393774304 | p04048 | Runtime Error | N, X = map(int, input())
if X == N//2:
print(N//2 * 3)
elif N % X == 0:
a = max(N-X, X)
b = min(N-X, X)
print(a + a // b * 2)
else:
print(0)
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s743460939 | p04048 | Runtime Error | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
def light_length(a:int, b:int) -> int:
if a == b:
return a
if a > b:
a,b = b,a
return 2*a + light_length(min(a,b-a), max(a,b-a))
n,x = li()
print(n + light_length(x,n-x)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s231663088 | p04048 | Runtime Error | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
def light_length(a:int, b:int) -> int:
if a == b:
return a
return 2*a + light_length(min(a,b-a), max(a,b-a))
n,x = li()
print(n + light_length(x,n-x)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s681918282 | p04048 | Runtime Error | N, X = [int(i) for i in input().split()]
import math
gcd = math.gcd(N, X)
print(gcd*(N//gcd-1)*3) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s811676658 | p04048 | Runtime Error | import math
n,x=map(int,input().strip().split())
print(3*(n-math.gcd(n,x))) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s241157045 | p04048 | Runtime Error | n,x=map(int,input().strip().split())
z=n-2*x
y=n-x
an=0
an+=3*x+y
an+=z*(x//z+1)
#x=x//z
#z-=2*x
while not z<x:
an+=z*(x//z+1)
if not x%z==0:
an+=1
z-=2*x
print(an) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s772768992 | p04048 | Runtime Error | #Include <bits/stdc++.h>
using namespace std;
int main(){
} | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s873049898 | p04048 | Runtime Error | a,b = map(int,input().split())
s = a/b
print(3b*(s-1)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s764156874 | p04048 | Runtime Error | from fractions import gcd
n,m=map(int,input().split())
print(3*(n-gcd(n,m)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s373246359 | p04048 | Runtime Error | n,x = map(int,input().split())
import fractions
print+(3 * (n-fractions.gcd(n,x))) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s255311561 | p04048 | Runtime Error | import math
[N, X] = list(map(int, input().split()))
print(int(3*(N-math.gcd(N,X))))
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s048338925 | p04048 | Runtime Error | # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(10000)
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
@mt
def slv(N, X):
if X == N//2:
return 3*X
ans = 0
if X > N//2:
X = N-X
ans = X
def f(n, x):
ans = 0
ans += n
n_x = n // x
ans += 2*n_x*x - x
if n_x % x != 0:
ans += f(x, n - n_x*x)
# print(n, x, n_x, 2*n_x*x - x, ans)
return ans
return ans + f(N-X, X)
def main():
N, X = read_int_n()
print(slv(N, X))
if __name__ == '__main__':
main()
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s154799118 | p04048 | Runtime Error | # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(10000)
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
@mt
def slv(N, X):
ans = 0
if X > N//2:
X = N-X
ans = X
def f(n, x):
ans = 0
ans += n
n_x = n // x
ans += 2*n_x*x - x
if n_x % x != 0:
ans += f(x, n - n_x*x)
# print(n, x, n_x, 2*n_x*x - x, ans)
return ans
return ans + f(N-X, X)
def main():
N, X = read_int_n()
print(slv(N, X))
if __name__ == '__main__':
main()
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s887363089 | p04048 | Runtime Error | n, x = map(int, input().split())
def func(a, b):
if a < b:
if b%a == 0:
return (b//a*2 - 1)*a
else:
return 2*a + func(a, b-a)
elif a > b:
if a%b == 0:
return (a//b*2 - 1)*b
else:
return 2*b + func(a-b, b)
else:
return a
if x == n/2:
print(3*x)
else:
print(x+(n-x)+func(x,n-x)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s430977308 | p04048 | Runtime Error | n, x = map(int, input().split())
def func(a, b):
if a < b:
if b%a == 0:
return b//a*2 - 1
else:
return 2*a + func(a, b-a)
else:
if a%b == 0:
return a//b*2 - 1
else:
return 2*b + func(a-b, b)
print(x+(n-x)+func(x,n-x)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s836690284 | p04048 | Runtime Error | n, x = map(int, input().split())
def func(a, b):
if a < b:
if b%a == 0:
return b/a*2 - 1
else:
return 2*a + func(a, b-a)
else:
if a%b == 0:
return a/b*2 - 1
else:
return 2*b + func(a-b, b)
if x == n/2:
print(3*x)
else:
print(x+(n-x)+func(x,n-x)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s111435103 | p04048 | Runtime Error | #!/usr/bin/env python3
import sys
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)
N, X = map(int, input().split())
def f(x, n):
debug(x,n)
# if 2*x == n:
# return 3*x
if x % (n-x) == 0:
return 3*x
if 2*x < n:
return f(x, n-x) + 3*x# n + x
a = x//(n-x) + 1
t = a*(n-x) - x
return f(n-x-t, n-x) + 3*x # + t
print(f(X, N))
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s256155392 | p04048 | Runtime Error | from math import gcd
N, X = map(int, input().split())
print(3 * (N - gcd(N, X)))
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s005205942 | p04048 | Runtime Error | """
a
+ -------
| b-a / / f(a, b) = 2*a + f(a, b-a)
| / / answer = N + f(X, N-X)
b ------- COMD(a < b)
| / \ /
| / \ /
| / \/
+ -------
"""
#--- define function ---#
def calc(a, b):
if a > b:
a, b = b, a
if a == b:
return a
else:
return 2 * a + calc(a, b - a)
#--- main ---#
N, X = input().split()
N, X = int(N), int(X)
ans = N + calc(X, N - X)
print(ans)
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s002545282 | p04048 | Runtime Error | def gcd(a,b):
if a%b==0:
return b
else:
return gcd(b,a%b)
N,X=map(int,input().split())
print(3*(N-gcd(N,X))
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s352506225 | p04048 | Runtime Error | def gcd(a,b):
if a%b==0:
return b
else:
return gcd(b,a%b):
N,X=map(int,input().split())
print(3*(N-gcd(N,X)) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s580800768 | p04048 | Runtime Error | from math import gcd
N, X=map(int, input().split())
print(3*(N - gcd(N, X)))
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s144543736 | p04048 | Runtime Error | def calc(a, b):
if a <= 0 or b <= 0:
return 0
if a == b:
return a
a, b = min(a, b), max(a, b)
return calc(b-a, a) + 2 * a
N, X = map(int, raw_input().split())
print calc(X, N-X) + N
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s510904734 | p04048 | Runtime Error | '''def f(a, b):
if a * b == 0:
return 0
res = f(min(a, b), max(a, b) % min(a, b)) + 2 * min(a, b) * (max(a,b)//min(a, b))
if(max(a, b) % min(a, b) == 0):
res -= 1
return res'''
def f(a, b):
if(a - b == 0):
return a
if(a * b == 0):
return 0
return 2 * min(a, b) + f(min(a, b), max(a,b) - min(a, b))
n, x = map(int, input().split())
res = n + f(n - x, x)
print(res)
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s002373403 | p04048 | Runtime Error | '''def f(a, b):
if a * b == 0:
return 0
res = f(min(a, b), max(a, b) % min(a, b)) + 2 * min(a, b) * (max(a,b)//min(a, b))
if(max(a, b) % min(a, b) == 0):
res -= 1
return res'''
def f(a, b):
minn = min(a, b)
maxx = max(a, b)
if(a - b == 0):
return a
if(a * b == 0):
return 0
return 2 * minn + f(minn, maxx - minn)
n, x = map(int, input().split())
res = n + f(n - x, x)
print(res)
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s949167797 | p04048 | Runtime Error | #! /bin/python
# coding:utf-8
import sys
def gcd(N, X):
while X:
N, X = X, N % X
return N
N = int(sys.argv[1])
X = int(sys.argv[2])
print 3 * (N - (gcd(N, X)))
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s131059688 | p04048 | Runtime Error | #! /bin/python
# coding:utf-8
def gcd(N, X):
while X:
N, X = X, N % X
return N
N, X = map(int, raw_input().split())
print = 3 * (N - (gcd(N, X)))
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s373823028 | p04048 | Runtime Error | L = map(int, raw_input().split())
n = L[0]
x = L[1]
res = n
a = x
b = n-x
flag = True
while flag :
if a > b:
q = a // b
a -= q*b
res += 2*q*b
elif b > a:
q = b // a
b -= q*a
res += 2*a*q
else:
res += a
flag = False
print(res) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s532964684 | p04048 | Runtime Error | def gcd(a,b):
if b == 0:
return a
return gcd(b,a%b)
N = int(raw_input())
k = int(raw_input())
#A = map(int, raw_input().split())
ans = gcd(N,k)
print 3*(N - ans) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s544302779 | p04048 | Runtime Error | N, X = int(input()), int(input())
print(X * 6) | 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s183172898 | p04048 | Runtime Error | #!/usr/bin/python3
import sys
sys.setrecursionlimit(1000000)
N, X = list(map(int, input().split()))
def f(a,b):
if a > b:
a,b = b,a
if b%a is 0:
return int(a*(2*(b/a)-1))
return int(2*a*int(b/a) + f(a,b%a))
print(N+f(N-X, X))
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s825196794 | p04048 | Runtime Error | #!/usr/bin/python3
import sys
sys.setrecursionlimit(100000)
N, X = list(map(int, input().split()))
def f(a,b):
if a > b:
a,b = b,a
if b%a is 0:
return int(a*(2*(b/a)-1))
return int(2*a*int(b/a) + f(a,b%a))
print(N+f(N-X, X))
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s754744111 | p04048 | Runtime Error | import sys
sys.setrecursionlimit(1500)
def f(x, y):
if x == 0:
return 0
if x == y:
return x
x, y = min(x, y), max(x, y)
return 2 * x + f(x, y - x)
N, X = list(map(int, input().split()))
print(f(X, N-X) + N)
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
s191680008 | p04048 | Runtime Error | import sys
sys.setrecursionlimit(1500)
def f(x, y):
if x == y:
return x
x, y = min(x, y), max(x, y)
return 2 * (y // x) * x + f(x, y % x)
N, X = list(map(int, input().split()))
print(f(X, N-X) + N)
| 5 2
| 12
| <span class="lang-en">
<p>Score : <var>500</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Snuke is conducting an optical experiment using mirrors and his new invention, the rifle of <em>Mysterious Light</em>.</p>
<p>Three mirrors of length <var>N</var> are set so that they form an equilateral triangle.
Let the vertices of the triangle be <var>a, b</var> and <var>c</var>.</p>
<p>Inside the triangle, the rifle is placed at the point <var>p</var> on segment <var>ab</var> such that <var>ap = X</var>.
(The size of the rifle is negligible.)
Now, the rifle is about to fire a ray of Mysterious Light in the direction of <var>bc</var>.</p>
<p>The ray of Mysterious Light will travel in a straight line, and will be reflected by mirrors, in the same ways as "ordinary" light.
There is one major difference, though: it will be also reflected by its own trajectory as if it is a mirror!
When the ray comes back to the rifle, the ray will be absorbed.</p>
<p>The following image shows the ray's trajectory where <var>N = 5</var> and <var>X = 2</var>.</p>
<div style="text-align: center;">
<img alt="btriangle.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/btriangle.png">
</img></div>
<p>It can be shown that the ray eventually comes back to the rifle and is absorbed, regardless of the values of <var>N</var> and <var>X</var>.
Find the total length of the ray's trajectory.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var>2≦N≦10^{12}</var></li>
<li><var>1≦X≦N-1</var></li>
<li><var>N</var> and <var>X</var> are integers.</li>
</ul>
</section>
</div>
<div class="part">
<section>
<h3>Partial Points</h3><ul>
<li><var>300</var> points will be awarded for passing the test set satisfying <var>N≦1000</var>.</li>
<li>Another <var>200</var> points will be awarded for passing the test set without additional constraints.</li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>N</var> <var>X</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the total length of the ray's trajectory.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>5 2
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>12
</pre>
<p>Refer to the image in the Problem Statement section.
The total length of the trajectory is <var>2+3+2+2+1+1+1 = 12</var>.</p></section>
</div>
</span> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.