fragment-header
fragment-markdown
홈
로그인
로그아웃
내 블로그
설정
로그인
AtCoder Beginner Contest 421-B (C++) Fibonacci Reversed
최초 업로드: 2025-08-30 14:17:12
최근 수정 시간: 2025-08-30 14:17:28
게시자: rlatjwls3333
카테고리: Atcoder
조회수: 15
# B - Fibonacci Reversed [문제 링크](https://atcoder.jp/contests/abc421/tasks/abc421_b) ## Problem Statement For a positive integer \$x\$, define \$f(x)\$ as follows: * Let \$s\_x\$ be the string obtained by representing \$x\$ in decimal notation (without leading zeros), and let \$\mathrm{rev}(s\_x)\$ be the string obtained by reversing \$s\_x\$. The value of \$f(x)\$ is the integer obtained by interpreting \$\mathrm{rev}(s\_x)\$ as a decimal representation of an integer. For example, when \$x=13\$, we have \$\mathrm{rev}(s\_x)=\texttt{31}\$, so \$f(x)=31\$; when \$x=10\$, we have \$\mathrm{rev}(s\_x)=\texttt{01}\$, so \$f(x)=1\$. Particularly, for any positive integer \$x\$, the value of \$f(x)\$ is a positive integer. You are given positive integers \$X\$ and \$Y\$. Define a sequence of positive integers \$A=(a\_1,a\_2,\dots,a\_{10})\$ as follows: * \$a\_1=X\$ * \$a\_2=Y\$ * \$a\_i=f(a\_{i-1}+a\_{i-2})\quad(i\ge 3)\$ Find the value of \$a\_{10}\$. ## Constraints * \$1\le X,Y\le 10^5\$ * All input values are integers. ## Input The input is given from Standard Input in the following format: \$X\ \ Y\$ ## Output Print the value of \$a\_{10}\$. ## 풀이 피보나치 항을 구하면서 reverse 연산을 해주었다. ``` c++ #include<bits/stdc++.h> using namespace std; typedef long long ll; ll rev(ll x) { string s = to_string(x); ll ret=0; for(int i=s.length()-1;i>=0;i--) ret = ret*10 + s[i]-'0'; return ret; } int main() { ios::sync_with_stdio(0); cin.tie(0); ll x, y; cin >> x >> y; for(int i=0;i<8;i++) { ll tmp = rev(x+y); x = y; y = tmp; } cout << y; } ```