fragment-header
fragment-markdown
홈
로그인
로그아웃
내 블로그
설정
로그인
Codeforces Round 1048-A (Div. 2) Maple and Multiplication
최초 업로드: 2025-09-08 18:20:28
최근 수정 시간: 2025-09-08 18:20:41
게시자: rlatjwls3333
카테고리: Codeforces
조회수: 11
# A. Maple and Multiplication [문제 링크](https://codeforces.com/contest/2139/problem/A) ## Problem Statement Maple has two positive integers $a$ and $b$. She may perform the following operation any number of times (possibly zero) to make $a$ equal to $b$: - Choose any positive integer $x$, and multiply either $a$ or $b$ by $x$. Your task is to determine the minimum number of operations required to make $a$ equal to $b$. It can be proven that this is always possible. ## Input Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). The description of the test cases follows. The first and only line of each test case contains two positive integers $a$ and $b$ ($1 \le a, b \le 1000$) — the numbers Maple currently has. ## Output For each test case, output a single integer representing the minimum number of operations Maple needs to make $a$ equal to $b$. ## 풀이 두 수가 같으면 0, 한 수가 다른 수의 배수라면 1, 그렇지 않으면 2번의 연산이 필요하다. ``` c++ #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while(t--) { ll a, b; cin >> a >> b; if(a<b) swap(a, b); if(a==b) cout << "0\n"; else if(a%b==0) cout << "1\n"; else cout << "2\n"; } } ```