fragment-header
fragment-markdown
홈
로그인
로그아웃
내 블로그
설정
로그인
Codeforces Round 1047-A (Div. 3) Collatz Conjecture
최초 업로드: 2025-09-07 17:48:09
최근 수정 시간: 2025-09-07 19:19:59
게시자: rlatjwls3333
카테고리: Codeforces
조회수: 6
# A. Collatz Conjecture [문제 링크](https://codeforces.com/contest/2137/problem/A) ## Problem Statement You are doing a research paper on the famous Collatz Conjecture. In your experiment, you start off with an integer $x$, and you do the following procedure $k$ times: - If $x$ is even, divide $x$ by $2$. - Otherwise, set $x$ to $3\cdot x + 1$. For example, starting off with $21$ and doing the procedure $5$ times, you get $21 \rightarrow 64 \rightarrow 32 \rightarrow 16 \rightarrow 8 \rightarrow 4 .$ After all $k$ iterations, you are left with the final value of $x$. Unfortunately, you forgot the initial value. Please output **any** possible initial value of $x$. ## Input Each test contains multiple test cases. The first line contains the number of test cases $t$ $(1 \le t \le 400)$. The description of the test cases follows. The first line of each test case contains two integers $k$ and $x$ $(1 \le k, x \le 20)$. ## Output For each test case, print any possible initial value on a new line. It can be shown that the answer always exists. ## 풀이 모든 연산이 2로 나누는 것이었다 가정하고 x에 $2^k$을 곱해주었다. ``` 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 k, x; cin >> k >> x; while(k--) x*=2; cout << x << '\n'; } } ```