Problems > Counting Euclid's Steps

Counting Euclid's Steps

Difficulty: 1200 2000 ms 128 MB

math

Run Euclid's algorithm on (A, B): repeatedly replace (a, b) by (b, a mod b) until b = 0. Print how many replacement steps happen.

Input: one line with two integers A and B.

Output: the number of steps until b becomes 0.

Constraints:

  • 1 ≤ A, B ≤ 1018

Sample Tests

Input 1
48 18
Output 1
3
Input 2
7 7
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.