Stern's Sequence
题号:NC226656
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Stern’s Triangle is similar to Pascal’s Triangle in that some values in each row are the sums of values in the previous row. In this case the previous row values are also copied down:

Row has  elements . Where:

 for  or 



 for 



If we align the  values so  is directly below , we get:
We see that for  sufficiently large, .

The sequence of these limiting values in called Stern’s Diatomic Sequnce:



It has the property that for every positve rational number, , there is exactly one value  for which .

For example: 

Write a program which takes as input a rational number  in lowest terms and outputs the value  for which  and . This number can get quite large, so out put it modulo the large prime 998,244,353


输入描述:

Input consists of a single line containing two relatively prime, space separated decimal integers, p and q (1 ≤ p, q ≤ 400000).

输出描述:

The single output line consists ofthe integer k, for which p = b(k) and q = b(k+1) printed modulo 998,244,353.
示例1

输入

复制
3 5

输出

复制
10
示例2

输入

复制
1234 763

输出

复制
525909