#AGC061F. [AGC061F] Perfect Strings

[AGC061F] Perfect Strings

Score : 20002000 points

Problem Statement

There are positive integers NN and MM.

A binary string ss is called good if all of the followings are satisfied:

  • ss is non-empty.
  • The number of 1s in ss is a multiple of NN.
  • The number of 0s in ss is a multiple of MM.

A good string is called perfect if it doesn't contain shorter good (contiguous) substrings. For example, if N=3N = 3 and M=2M = 2, then strings 111, 00 and 10101 are perfect, but 0000 and 11001 are not.

One can show that for any N,MN, M the number of perfect strings is finite. Find this number modulo 998244353998\,244\,353.

Constraints

  • 1N,M401 \leq N, M \leq 40
  • All values in the input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

Output

Print the answer.

2 2
4

The perfect strings are 00, 0101, 1010, 11.

3 2
7

The perfect strings are 00, 01011, 01101, 10101, 10110, 11010, 111.

23 35
212685109