Official
A - Mod While Positive Editorial by en_translator
Actually repeatedly perform the operation while \(M\) is not \(0\), which can be achieved by using a while statement.
Note that dividing \(N\) by \(M\) makes it strictly smaller than \(M\), so an operation always makes \(M\) smaller, and at most \(M\) operations makes \(M = 0\).
Sample code
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int ans = 0;
while (m > 0) {
m = n % m;
ans++;
}
cout << ans << '\n';
}
posted:
last update: