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:
%20%3D%20S(n%2C%20k))
for
If we align the
)
values so
)
is directly below
)
, we get:
We see that for

sufficiently large,
%20%3D%20S(n%2C%20k))
.
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
%2Fb(k%2B1))
.
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.