B - Fibonacci Reversed Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

正整数 x に対し、f(x) を以下のように定義します。

  • x を(先頭に余分な 0 をつけずに)十進表記して得られる文字列を s_xs_x を反転して得られる文字列を \text{rev}(s_x) とおく。 f(x) の値は、\text{rev}(s_x) を整数の十進表記としてみなすことで得られる整数である。

例えば、x=13 のとき \text{rev}(s_x)=\ 31 より f(x)=31 であり、x=10 のとき \text{rev}(s_x)=\ 01 より f(x)=1 です。 特に、どのような正整数 x に対しても f(x) の値は正整数です。

正整数 X,Y が与えられます。 正整数列 A=(a_1,a_2,\dots,a_{10}) を以下のように定義します。

  • a_1 = X
  • a_2 = Y
  • a_i = f(a_{i-1}+a_{i-2})\ (i\geq 3)

a_{10} の値を求めてください。

制約

  • 1\leq X,Y \leq 10^5
  • 入力は全て整数

入力

入力は以下の形式で標準入力から与えられる。

X Y

出力

a_{10} の値を出力せよ。


入力例 1

1 1

出力例 1

415

A の各要素の値は以下の通りです。

  • a_1=1
  • a_2=1
  • a_3=2
  • a_4=3
  • a_5=5
  • a_6=8
  • a_7=31
  • a_8=93
  • a_9=421
  • a_{10}=415

よって 415 を出力します。


入力例 2

3 7

出力例 2

895

入力例 3

90701 90204

出力例 3

9560800101

Score : 200 points

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 \text{rev}(s_x) be the string obtained by reversing s_x. The value of f(x) is the integer obtained by interpreting \text{rev}(s_x) as a decimal representation of an integer.

For example, when x=13, we have \text{rev}(s_x)= 31, so f(x)=31; when x=10, we have \text{rev}(s_x)= 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})\ (i\geq 3)

Find the value of a_{10}.

Constraints

  • 1\leq X,Y \leq 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}.


Sample Input 1

1 1

Sample Output 1

415

The values of the elements of A are as follows:

  • a_1=1
  • a_2=1
  • a_3=2
  • a_4=3
  • a_5=5
  • a_6=8
  • a_7=31
  • a_8=93
  • a_9=421
  • a_{10}=415

Thus, print 415.


Sample Input 2

3 7

Sample Output 2

895

Sample Input 3

90701 90204

Sample Output 3

9560800101