AT_abc460_a.Mod While Positive
入门
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given positive integers N and M.
If the following operation is repeated while the value of M is not 0, find the number of operations performed.
- Let x be the remainder when N is divided by M. Replace the value of M with x.
It can be proved that M becomes 0 after a finite number of operations.
给定正整数 N 和 M。
当 M 的值不为 0 时,重复执行以下操作,求总共执行的操作次数:
- 令 x 为 N 除以 M 的余数,将 M 的值替换为 x。
可以证明:经过有限次操作后,M 必然变为 0。
输入格式
The input is given from Standard Input in the following format:
N M
输入从标准输入中以如下格式给出:
N M
输出格式
Output the answer.
输出答案。
输入输出样例
输入#1
8 5
输出#1
3
输入#2
14 6
输出#2
2
输入#3
460 33
输出#3
5
说明/提示
Sample 1 Explanation:
Initially, N=8 and M=5.
The remainder when 8 is divided by 5 is 3, so M=3 after one operation.
The remainder when 8 is divided by 3 is 2, so M=2 after two operations.
The remainder when 8 is divided by 2 is 0, so M=0 after three operations.
Thus, output 3 as the answer.
Constraints
- 1≤N,M≤1000
- All input values are integers.
样例 1 解释:
初始时,N=8,M=5。
8 除以 5 的余数为 3,因此经过一次操作后 M=3。
8 除以 3 的余数为 2,因此经过两次操作后 M=2。
8 除以 2 的余数为 0,因此经过三次操作后 M=0。
因此,输出答案 3。
约束条件
- 1≤N,M≤1000
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?