AT_abc460_a.Mod While Positive

入门

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given positive integers NN and MM.

If the following operation is repeated while the value of MM is not 00, find the number of operations performed.

  • Let xx be the remainder when NN is divided by MM. Replace the value of MM with xx.

It can be proved that MM becomes 00 after a finite number of operations.

给定正整数 NN 和 MM。

当 MM 的值不为 00 时,重复执行以下操作,求总共执行的操作次数:

  • 令 xx 为 NN 除以 MM 的余数,将 MM 的值替换为 xx。

可以证明:经过有限次操作后,MM 必然变为 00。

输入格式

The input is given from Standard Input in the following format:

NN MM

输入从标准输入中以如下格式给出:

NN MM

输出格式

Output the answer.

输出答案。

输入输出样例

  • 输入#1

    8 5

    输出#1

    3
  • 输入#2

    14 6

    输出#2

    2
  • 输入#3

    460 33

    输出#3

    5

说明/提示

Sample 1 Explanation:
Initially, N=8N = 8 and M=5M = 5.

The remainder when 88 is divided by 55 is 33, so M=3M = 3 after one operation.

The remainder when 88 is divided by 33 is 22, so M=2M = 2 after two operations.

The remainder when 88 is divided by 22 is 00, so M=0M = 0 after three operations.

Thus, output 33 as the answer.

Constraints

  • 1≤N,M≤10001 \leq N, M \leq 1000
  • All input values are integers.

样例 1 解释:
初始时,N=8N = 8,M=5M = 5。

88 除以 55 的余数为 33,因此经过一次操作后 M=3M = 3。

88 除以 33 的余数为 22,因此经过两次操作后 M=2M = 2。

88 除以 22 的余数为 00,因此经过三次操作后 M=0M = 0。

因此,输出答案 33。

约束条件

  • 1≤N,M≤10001 \leq N, M \leq 1000
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页