submission_id
string
problem_id
string
status
string
code
string
input
string
output
string
problem_description
string
s030726620
p04048
Accepted
#B n,x = [int(i) for i in input().split()] ans = x a = x p = n-x while(1): q,r = divmod(a,p) ans += p * 2* q if r==0: print(ans) break else: ans += p ans += r a = p -r p = r
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>
s337939583
p04048
Accepted
import fractions N,X=map(int,input().split()) print(int(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>
s059552557
p04048
Accepted
# --*-coding:utf-8-*-- N, X = map(int, input().split()) S = N a = N - X b = X while b > 0: c = a%b S += 2*(a-c) a,b = b,c print(S-a)
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>
s935131823
p04048
Accepted
from fractions 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>
s566697952
p04048
Accepted
import sys input = sys.stdin.readline sys.setrecursionlimit(1000000) from collections import deque, Counter def getN(): return int(input()) def getList(): return list(map(int, input().split())) import math INF = 10**10 def bfs(graph, visited, position, root): visited[root] = 1 position[root] = 0 deq = deque([root]) while(deq): cur = deq.pop() # print(cur) for nxt, dist in graph[cur]: if position[cur] + dist != position[nxt]: if position[nxt] != INF: return False else: position[nxt] = position[cur] + dist if not visited[nxt]: deq.append(nxt) visited[nxt] = 1 return True def main(): n,x = getList() ans = n mx, mn = x, n - x if mx < mn: mx,mn = mn, mx # print(mx, mn) while(True): if mx % mn == 0: ans += 2 * mn * (mx // mn) - mn break else: ans += mn * 2 * (mx // mn) mx, mn = mn, mx % mn print(ans) 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>
s068524854
p04048
Accepted
N, X = map(int, input().split()) from fractions import gcd 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>
s156187298
p04048
Accepted
n, x = map(int, input().split()) ans = n y, x = n-x, x if x > y: y, x = x, y while True: q, r = divmod(y, x) if r == 0: ans += (2*q-1)*x break ans += 2*q*x y, x = x, r 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>
s357671186
p04048
Accepted
from fractions 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>
s664228161
p04048
Accepted
n,x = map(int,input().split()) ans = n A = x B = n-x while A and B: if A<B: A,B = B,A k = A//B if A%B: ans += k*B*2 else: ans += B*(k*2-1) A = A%B 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>
s927215127
p04048
Accepted
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N,X = map(int,read().split()) def F(A,B): # (A,B)の平行四辺形の120度の対角から出た状態 if A > B: A,B = B,A q,r = divmod(B,A) if not r: return A * (q+q-1) return F(A,r) + q * (2 * A) answer = N + F(X,N-X) print(answer)
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>
s021348992
p04048
Accepted
def run(): N, X = map(int, input().split()) y = N-X ans = N while True: y, X = max(y, X), min(y, X) a = y//X b = y%X ans += a*X*2 if b == 0: break y, X = X, b 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>
s432672785
p04048
Accepted
def main(): n, x = map(int, input().split()) ans = n a, b = min(x, n-x), max(x, n-x) while a > 0: ans += 2*(b//a)*a a, b = b % a, a print(ans-b) 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>
s584383797
p04048
Accepted
n,x = [int(i) for i in input().split()] length = n n=n-x while True: t=n//x length+=2*t*x a=n n=x x=a-t*x if x==0: length-=n 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>
s831954461
p04048
Accepted
#!/usr/bin/env python3 import sys from math import sqrt def solve(N: int, X: int): # 平行四辺形の面積 answer = N a,b = max(N-X,X),min(N-X,X) while True: answer += 2*(a//b)*b if a%b == 0: answer -= b break a,b = b,a%b print(answer) return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int X = int(next(tokens)) # type: int solve(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>
s385915610
p04048
Accepted
import sys N,X = map(int,input().split()) ans = 0 oldx = 0 if N > 2 * X: ans = N N = N - X elif N == 2 * X: ans = 3 * X print (ans) sys.exit() else: ans = N oldx = X X = N - X N = oldx while True: #print (N,X,ans) if N % X == 0: ans += ((N // X) * 2 - 1) * X break else: ans += ((N // X) * 2 * X) oldx = X X = N % X N = oldx 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>
s183083130
p04048
Accepted
N, X = map(int, input().split()) ans = N a, b = max(X, N-X), min(X, N-X) while b: q, r = divmod(a, b) if r == 0: ans += b * (2 * q - 1) else: ans += b * 2 * q a, b = max(b, r), min(b, r) 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>
s375248954
p04048
Accepted
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd from bisect import bisect_left from heapq import heappush, heappop from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N, X = MAP() 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>
s924381346
p04048
Accepted
N, X = map(int, raw_input().strip().split()) ans = N a, b = N-X, X if b > a: a, b = b, a while b > 0: k = 2 * (a / b) if a % b == 0: k -= 1 ans += k * b a, b = b, a % b 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>
s819723548
p04048
Accepted
N, X = map(int, input().split()) def solve(edge, width, ans): a, b = divmod(width, edge) if b == 0: return ans+edge*(2*a-1) return solve(width-edge*a, edge, ans + edge*2*a) print(solve(min(X,N-X), max(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>
s755419303
p04048
Accepted
from fractions import* 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>
s711075829
p04048
Accepted
import sys import fractions from collections import Counter, deque, defaultdict from math import factorial import heapq, bisect import math import itertools sys.setrecursionlimit(10 ** 5 + 10) INF = 10**15 +5 def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) n,x = MAP() def cal(a,b): if a > b: aa = a a = b b = aa ref = b//a if b%a == 0: return a*(2*ref-1) return a*2*ref + cal(b%a,a) print(n + cal(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>
s824511282
p04048
Accepted
n, x = map(int, input().split()) ans = 0 def rec(a,b): global ans if a > b: a,b = b,a if b%a == 0: k = b//a ans += (2*k-1)*a else: k = b//a ans += 2*k*a rec(a, b%a) ans += n rec(n-x,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>
s052510646
p04048
Accepted
import sys sys.setrecursionlimit(10000000) def input(): return sys.stdin.readline()[:-1] from bisect import * from collections import * from heapq import * import itertools INF = 10**10 MOD = 10**9+7 N, X = map(int, input().split()) a, b, ans = max(X, N-X), min(X, N-X), N while 1: ans += 2*b*(a//b) a, b = b, a%b if b == 0: ans -= a break 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>
s841063452
p04048
Accepted
# -*- 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() # 最初のN以外は、平行四辺形を小さくしていくと考える def rec(a, b): if b == 0: # 最後に割り切れた時は半分でいいので減らす return -a a, b = min(a, b), max(a, b) # 同じだけ小さくする所はまとめてやる return a*2*(b//a) + 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>
s247693168
p04048
Accepted
def gcd(a,b): while b:a,b=b,a%b return a n,x=map(int,input().split());print((n-gcd(n,x))*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>
s415504689
p04048
Accepted
def gcd(a,b): while b:a,b=b,a%b return a n,x=map(int,input().split());print((n-gcd(n,x))*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>
s311931212
p04048
Accepted
# -*- 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() # 最初のN以外は、平行四辺形を小さくしていくと考える def rec(a, b): a, b = min(a, b), max(a, b) if a == 0: # 最後に割り切れた時は半分でいいので減らす return -b # 同じだけ小さくする所はまとめてやる return a*2*(b//a) + 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>
s139965746
p04048
Accepted
n, x = map(int, input().split()) ans = n wall_side = n - x light_length = n - (n - x) while True: if wall_side % light_length == 0: ans += (2 * (wall_side // light_length - 1) + 1) * light_length break else: ans += 2 * (wall_side // light_length) * light_length wall_side, light_length = light_length, wall_side % light_length 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>
s506231618
p04048
Accepted
# -*- coding: utf-8 -*- import sys if sys.version_info.minor >= 5: from math import gcd else: from fractions import gcd 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() print((N-gcd(N, X))*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>
s504779492
p04048
Accepted
n, x = map(int, input().split()) a, b = max(n-x,x),min(n-x,x) res = a+b while b!=0: q = a//b r = a%b res += (b*2)*q if (r==0): res -= b a, b = b, r 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>
s779236580
p04048
Accepted
import sys input = sys.stdin.readline def main(): N, X = map(int, input().split()) ans = N min_ = min(X, N-X) max_ = max(X, N-X) while min_ != 0: # print(max_, min_) ans += (max_ // min_) * 2 * min_ tmp = max_ % min_ max_ = min_ min_ = tmp ans -= max_ print(ans) 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>
s860314589
p04048
Accepted
N, X = map(int, input().split()) q, p = sorted((N - X, X)) r = 1 while r: p, r = divmod(p, q) N += (2 * p - (r == 0)) * q p, q = q, r print(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>
s683154326
p04048
Accepted
N,X=map(int,input().split()) ans=0 a,b=max(N-X,X),min(N-X,X) r=1 while r: r=a%b ans+=3*b*(a//b) a,b=b,r 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>
s288208467
p04048
Accepted
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) N,X = map(int,input().split()) def F(x,y): """ x,yの平行四辺形。対角にたどり着くまでの距離 """ if x>y: x,y = y,x q,r = divmod(y,x) if r == 0: return (2*q-1)*x return 2*q*x + F(x,y%x) answer = N + F(X,N-X) print(answer)
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>
s804693083
p04048
Accepted
import sys import heapq from operator import itemgetter from collections import deque, defaultdict from bisect import bisect_left, bisect_right input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) MOD = 10**9 + 7 def sol(): N, X = map(int, input().split()) ans = N A = max(N - X, X) B = min(N - X, X) while B: q = A // B r = A % B ans += B * 2 * q if r == 0: ans -= B A = B B = r print(ans) sol()
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>
s134463842
p04048
Accepted
n,x=map(int,input().split()) ans=n M=max(n-x,x) m=min(n-x,x) while(True): r=M%m q=int((M-r)/m) if(r==0): ans+=(2*q-1)*m break else: ans+=2*q*m M=m m=r 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>
s473109116
p04048
Accepted
from fractions import*;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>
s733850664
p04048
Accepted
a,x=map(int,input().split()) q,p=sorted((a-x,x)) while q: a+=(p//q*2-(p%q<1))*q p,q=q,p%q print(a)
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>
s516282759
p04048
Accepted
a,x = map(int,input().split()) q,p = sorted((a-x,x)) r = 1 while r: p,r = divmod(p,q) a += (2*p-(r==0))*q p,q = q,r print(a)
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>
s413387511
p04048
Accepted
n,x=[int(i) for i in input().split()] ans=n a,b=min(x,n-x),max(x,n-x) while a: c=b%a ans+=(b-c)*2 a,b=c,a ans-=b 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>
s129631581
p04048
Accepted
N,X = map(int,input().split()) ans = N x=X y=N-X if x<y:x,y=y,x while y!=0: k = x//y ans += y*k*2 x,y = y,x%y ans -= 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>
s978395756
p04048
Accepted
n,x=map(int,input().split()) c=n def sol(a,b): global c if a==b:c+=a elif a%b==0:c+=b*(2*(a//b)-1) elif b%a==0:c+=a*(2*(b//a)-1) elif a>b: c+=b*(a//b)*2 sol(a-a//b*b,b) else: c+=a*(b//a)*2 sol(a,b-b//a*a) sol(x,n-x) print(c)
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>
s900302027
p04048
Accepted
N, X = map(int, input().split()) ans = N a = N - X b = X while a != b: if a >= b: a, b = b, a if b%a != 0: ans += 2 * a * (b//a) b = b%a else: ans += 2 * a * (b//a - 1) b = a print (ans + a)
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>
s509274593
p04048
Accepted
n,x = map(int,input().split()) import math def f(x,y): a = min(x,y) b = max(x,y) if a == 0: return 0 elif b%a == 0: return 2*b-a else: return 2*a*math.floor(b/a) + f(a,b%a) 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>
s915113440
p04048
Accepted
def gcd(a, b): while b: a, b = b, a % b return a def main(): hen, start=map(int,input().split()) koyakusuu = gcd(hen, start) ans = koyakusuu * 3 * (hen // koyakusuu - 1) print(ans) 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>
s554996164
p04048
Accepted
N, X = map(int, input().split()) # 横に2個 X = X if 2*X <= N else N - X a = X b = (N-X)//X c = (N-X)%X ans = 0 while True: ans += a*b*3 if c == 0: break a, b, c = c, a//c, a%c 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>
s794365330
p04048
Accepted
def trapizoid_light(side, bottom): if (bottom - side) % side == 0: return 2 * (bottom - side) next_side = bottom % side return 2 * ((bottom - side) // side * side) + side + next_side + trapizoid_light(next_side, side) N, X = map(int, input().split()) if N % 2 == 0 and N // 2 == X: print(3 * X) else: if X <= N // 2: print(2 * X + N - X + trapizoid_light(X, N - X)) else: print(2 * (N - X) + X + trapizoid_light(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>
s349108191
p04048
Accepted
N,X=map(int,input().split()) def gcd(a,b): while a%b>0: a,b=b,a%b return b g=gcd(N,X) ans=g*3*(N//g-1) 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>
s154517879
p04048
Accepted
def main(): n, x = map(int, input().split()) remainder = n - (2 * x) if remainder == 0: print(3 * x) return if remainder < 0: n, x = x, (n - x) else: n -= x ans = 0 while True: num = n // x ans += (3 * x) * num rem = n % x if rem == 0: break n, x = x, rem print(ans) 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>
s451595171
p04048
Accepted
def gcd(a: int, b: int)->int: if a < b: a, b = b, a return a if b == 0 else gcd(b, a % b) def mysterious_light(N: int, X: int)->int: g = gcd(N, X) return 3 * max(N-g, g) if __name__ == "__main__": N, X = map(int, input().split()) ans = mysterious_light(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>
s805954247
p04048
Accepted
N,X = map(int,input().split()) x = X y = N-X if x<y: x,y = y,x res = N while y>0: x,y = y,x m = x*(y//x) res += m*2 y -= m res -= 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>
s362373879
p04048
Accepted
N,X = map(int,input().split(" ")) Y,X = sorted([N - X,X]) s = 0 while Y: s += (X//Y)*Y*3 Y,X = [X%Y,Y] print(s)
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>
s789912000
p04048
Accepted
def calc(a,b,ans): if b==0: return ans else: return calc(b,a%b,ans+b*(a//b)*3) n,x=map(int,input().split()) n=n-x n,x=max(n,x),min(n,x) print(calc(n,x,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>
s874701479
p04048
Accepted
N,X = map(int,input().split(" ")) Y,X = sorted([N - X,X]) s = 0 while Y: s += (X//Y)*Y*3 Y,X = [X%Y,Y] print(s)
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>
s877696083
p04048
Accepted
N,X = map(int, input().split()) if N/2 == X: l = X*3 elif N/2 > X: l = N x = X n = N - X while x > 0: l += (n//x)*2*x c = x x = n%x n = c l -= n else: l = N x = X n = N - X while x > 0: l += (n//x)*2*x c = x x = n%x n = c l -= 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>
s068437222
p04048
Accepted
n, x = [int(i) for i in input().split()] cnt=0 short = min(x,n-x) long = max(x, n-x) cnt += n #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>
s217425975
p04048
Accepted
def f(a,b): if a==b: d=0 ret = a elif a < b: d = b//a if b%a == 0: ret = a*(2*d -1) else: ret = 2*a*d + f(a,b%a) else: d = a//b if a%b == 0: ret = b*(2*d -1) else: ret = 2*b*d + f(a%b,b) #print(a,b,d,ret) 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>
s720742160
p04048
Accepted
"""B - Mysterious Light""" N,X=(int(i) for i in input().split()) def MysteriousLight(tmp,rem): while rem: tmp, rem= rem,tmp%rem return tmp print(3*(N-MysteriousLight(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>
s578241618
p04048
Accepted
N, X = list(map(int, input().split())) ans = N a, b = sorted([X, N - X]) while True: if b % a == 0: ans += (int(b / a) * 2 - 1) * a break else: ans += int(b // a) * a * 2 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>
s312454322
p04048
Accepted
# -*- coding: utf-8 -*- def rli(): return list(map(int, input().split())) def solve(n, x): if x < n - x: x = n - x w = n - x t = (w - (x % w)) % w res = (x + w - 1) // w * 3 * w - t * 3 if t != 0: res += solve(w, w - t) return res def main(): n, x = rli() print(solve(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>
s269810115
p04048
Accepted
n, x = map(int, input().split()) total = n a = x b = n - x while a > 0: total += (a * 2) * (b // a) a, b = b % a, a print(total - b)
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>
s583034545
p04048
Accepted
N,x=map(int,input().split()) x=min(x,N-x) rem=[N-x,x] len=x ans=N i=1 while True: i=(i+1)%2 ans+=2*(rem[i]//len)*len rem[i]=rem[i]%len if rem[i]!=0: len=rem[i] else: break print(ans-len)
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>
s143554382
p04048
Accepted
N,X=map(int,input().split()) def f(a,b): if a>b: return f(b,a) if b%a==0: return a*(2*(b//a) - 1) return 2*(b//a)*a + f(b%a,a) 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>
s558246325
p04048
Accepted
import sys stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) nn = lambda: list(stdin.readline().split()) ns = lambda: stdin.readline().rstrip() n,x = na() def loop(a,b): h = max(a,b) w = min(a,b) if h%w == 0: return int((2*h/w-1)*w) else: m = h%w q = h//w return 2*q*w + loop(m,w) print(loop(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>
s140575390
p04048
Accepted
def f(a,b): a,b=min(a,b),max(a,b) if b%a==0: return (2*b//a-1)*a else: return 2*a*(b//a)+f(a,b%a) n,x=map(int,input().split()) 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>
s861375142
p04048
Accepted
#!usr/bin/env python3 from collections import defaultdict from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS():return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n):l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n):l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n):l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n):l[i] = SR() return l mod = 1000000007 #A """ n = I() l = LI() l.sort() ans = 0 for i in range(n): ans += l[2*i] print(ans) """ #B def gcd(a,b): if a == 0: return b return gcd(b%a,a) n,x = LI() print((n-gcd(n,x))*3) #C #D #E #F #G #H #I #J #K #L #M #N #O #P #Q #R #S #T
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>
s380813222
p04048
Accepted
n, x = map(int, input().split()) p = n if x * 2 > n: x = n - x ans = 0 while(x > 0): if n == p: ans += 3 * x * (n // x - 1) else: ans += 3 * x * (n // x) n, x = 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>
s101809950
p04048
Accepted
n,x = map(int,input().split()) def gcd(a,b): if a%b == 0: return b else: return gcd(b,a%b) k = gcd(n,x) if k == 1: print((n-1)*3) else: print((int(n/k)-1)*3*k)
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>
s037011222
p04048
Accepted
def main(): n,x=map(int,input().split()) a,b=n-x,x if(a<b): a,b=b,a path_length = calc_path(a,b,n) print(path_length) def calc_path(a1,b1,c1): q , mod=divmod(a1,b1) count=0 if mod==0: c2=c1+2*b1*q-b1 return c2 else: count=count+1 c2=c1+2*b1*q a2=a1-b1*q b2=b1 if(a2<b2): a2,b2=b2,a2 return calc_path(a2,b2,c2) 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>
s552887138
p04048
Accepted
def gcd(x,y): if(x < y): x,y = y,x if(y == 0): return x return gcd(y,x % y) n,x = map(int,input().split()) g = gcd(n,x) n //= g print((3*n-3)*g)
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>
s994394061
p04048
Accepted
# coding:utf-8 import sys INF = float('inf') MOD = 10 ** 9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return input() def main(): n, x = LI() b, a = sorted([x, n - x]) ans = a + b while b: q, mod = divmod(a, b) ans += (2 * q - (not mod)) * b a, b = b, mod return ans print(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>
s525625050
p04048
Accepted
import sys sys.setrecursionlimit(10 ** 9) N, X = map(int, input().split()) def rec(a, b): a, b = min(a, b), max(a, b) if b % a == 0: return (2 * a) * (b // a) - a else: return (2 * a) * (b // a) + rec(a, b % a) print(X + N - X + 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>
s588314224
p04048
Accepted
n,x = map(int,input().split()) x = min(x,n-x) n = n - x ans = 0 while True: new_x = n%x new_n = n//x if new_x ==0: print(ans+x*new_n*3) exit() else: ans = ans + x*new_n*3 n = x x = new_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>
s503683315
p04048
Accepted
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 elif a > b: s += (a // b) * 2 * b return solve(s, a % b, b) else: s += (b // a) * 2 * a return solve(s, 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>
s963121308
p04048
Accepted
n, x = map(int, input().split()) def g(a, b): if a%b == 0:return b return g(b, a%b) ans = 3*(n-g(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>
s338757392
p04048
Accepted
def gcd(a, b): if b == 0: return a 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>
s522572407
p04048
Accepted
n, x = map(int, input().split()) if (x > n // 2 and n % 2 == 0) or (x > (n + 1) // 2 and n % 2 == 1): x = n - x A = n - x B = x k = 0 m = -1 ans = n while m != 0: k = A // B m = A % B ans += B * k * 2 if m == 0: ans -= B A = B B = m 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>
s249034321
p04048
Accepted
import sys sys.setrecursionlimit(100000) from math import floor n,x=map(int,input().split()) ans=0 def f(x,y): if y%x==0: return (y//x-1)*2*x+x return 2*x*(y//x)+f(y%x,x) print(n+f(min(x,n-x),max(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>
s876361459
p04048
Accepted
import fractions n,x = (int(i) for i in input().split()) ans = fractions.gcd(n,x) 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>
s381260099
p04048
Accepted
N, X = map(int, input().split()) l = 0 if X < N-X: long = N - X short = X else: long = X short = N - X l += N while True: l += long // short * short * 2 x = long % short if x == 0: l -= short break long = short short = x 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>
s156822289
p04048
Accepted
def gcd(a, b): while b: a, b = b, a % b return a li = [int(i) for i in input().split(" ")] res = (li[0] // gcd(li[0], li[1]) -1) * 3 * 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>
s950561751
p04048
Accepted
N, X = map( int, input().split()) a, b = max(X, N-X), min(X, N-X) #a >= b ans = a + b if a == b: ans += a while a != b: if a%b == 0: ans += (a//b*2-1)*b break ans += a//b*2*b a, b = b, a%b 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>
s410601602
p04048
Accepted
n, x = map(int, input().split()) # a <= b def f(a, b): if b % a == 0: return (b // a) * 2 * a - a return (b // a) * a * 2 + f(b % a, a) print(n + f(min(x, n - x), max(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>
s598988198
p04048
Accepted
from fractions 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>
s783693060
p04048
Accepted
N,X = map(int,input().split()) def f(a,b) : if a > b : a,b = b,a if b % a == 0 : return 2*(b//a-1)*a + a else : return 2*(b//a)*a + f(a,b%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>
s194143299
p04048
Accepted
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 gcd(a,b): if a%b == 0: return b else: return gcd(b, a%b) def rec(a: int, b: int) -> int: mx = max(a,b) mn = min(a,b) if gcd(a,b) == mn: return (2 * (mx // mn) - 1) * mn else: return (2 * (mx // mn) * mn) + rec(mn, mx - 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>
s917308530
p04048
Accepted
N,X = map(int,input().split()) ans = N a,b = X,N-X if a>b: a,b = b,a while a: d,m = divmod(b,a) ans += d*a*2 a,b = m,a if a>b: a,b = b,a ans -= b 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>
s038072391
p04048
Accepted
# your code goes here from math import floor N, X = [int(x) for x in input().split()] y = N-X x = X L = X while x > 0: # k = 2*floor(y/x) k, z = divmod(y, x) # dL = x*(2*k-1)+y L += x*(2*k-1)+y # print(x, y, k, dL) y, x = (x, z) #L += y 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>
s825981109
p04048
Accepted
import sys sys.setrecursionlimit(10**7) def f(a,b): if a==b:return a if not a<b:a,b=b,a return 2*(b//a)*a+f(a,b%a) if b%a else 2*(b//a)*a-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>
s590590950
p04048
Accepted
N, X = map(int, input().split()) TotalLength = N Vert = N-X Hor = X Fin = False while not Fin: if Vert < Hor: if Hor % Vert == 0: TotalLength += (2 * (Hor//Vert) - 1) * Vert Fin = True else: TotalLength += 2 * (Hor//Vert) * Vert Hor %= Vert else: if Vert % Hor == 0: TotalLength += (2 * (Vert//Hor) - 1) * Hor Fin = True else: TotalLength += 2 * (Vert//Hor) * Hor Vert %= Hor print(TotalLength)
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>
s425456402
p04048
Accepted
n, a = map(int, input().split(' ')) b = n - a if a < b: a, b = b, a ans = n while b: q = a // b ans += 2 * q * b a %= b a, b = b, a ans -= 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>
s270601312
p04048
Accepted
# %%time import numpy as np n, x = list(map(int, input().split())) s = 0 a = [n-x, x] s += n # print(a,s) while True: # if a[0] == a[1]: # s += a[0] # break # else: mi = np.min(a) ar = np.argmax(a) num = a[ar]//mi a[ar] -= mi * num s += 2 * mi * num # print(a, s) if np.min(a) == 0: s -= mi break print(s)
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>
s573567027
p04048
Accepted
def f(a, b): if a > b: a, b = b, a if a == 0: return -b return 2*(b/a)*a + f(a, b%a) n, x = map(int, raw_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>
s957027440
p04048
Accepted
#最大公約数 def gcd(a,b): if a==b: return b elif a%b== 0: return b else: return gcd(b,a%b) import math def func(a,b): if a<=b : if b%a != 0: return 2*math.floor(b/a)*a+func(a,b%a) else: return 2*(math.floor(b/a))*a-a else: return func(b,a) N,X = map(int,input().split()) dis =N dis += func(N-X,X) dis1 = 3*(N-gcd(N,X)) print(dis)
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>
s106590695
p04048
Accepted
n,x = map(int,input().split()) ans = 0 if 2*x == n: ans = 3*x else: ans += n a = x b = n - x while True: ans += (a//b)*2*b c = b b = a%b a = c if b == 0: ans -= a break 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>
s916453423
p04048
Accepted
n,x = map(int,input().split()) ans = 0 if 2*x == n: ans = 3*x else: ans += n a = x b = n - x while True: ans += (a//b)*2*b c = b b = a%b a = c if b == 0: ans -= a break 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>
s049975237
p04048
Accepted
N,X = map(int,input().split()) ans = N a,b = X, N-X if a > b: a,b = b,a while b: d,m = divmod(a,b) ans += 2*b*d a,b = b,m ans -= 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>
s875310760
p04048
Accepted
N, X = map(int, input().split()) ans = N a, b = sorted((X, N - X)) while a != 0: if b % a == 0: ans += 2 * (b // a - 1) * a + a print(ans) break else: ans += 2 * (b // a) * a a, b = sorted((a, b % a))
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>
s574531356
p04048
Accepted
def f(n, x): if n % x == 0: return (n // x * 2 - 1) * x else: return (n // x * 2) * x + f(x, n % x) n, x = map(int,input().split()) ans = n + f(n - x, 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>
s945542266
p04048
Accepted
N, X = map(int, input().split()) ans = N a, b = sorted((X, N - X)) while a != 0: if b % a == 0: ans += 2 * (b // a - 1) * a break else: ans += 2 * (b // a) * a a, b = sorted((a, b % a)) print(ans + a)
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>