#abc256g. G - Black and White Stones

G - Black and White Stones

Score : 600600 points

问题描述

存在一个边长为 DD 的正 NN 边形。

从一个顶点出发,我们在圆周上每隔 11 个单位放置黑色或白色的石子。因此,每个 NN 边形的边将会有 (D+1)(D+1) 个石子,总共放置 NDND 个石子。

有多少种方法可以放置石子,使得所有边上的白色石子数量相同?请在模 998244353998244353 的意义下求出方案数。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There is a regular NN-gon with side length DD.

Starting from a vertex, we place black or white stones on the circumference at intervals of 11. As a result, each edge of the NN-gon will have (D+1)(D+1) stones on it, for a total of NDND stones.

How many ways are there to place stones so that all edges have the same number of white stones on them? Find the count modulo 998244353998244353.

Constraints

  • 3N10123 \leq N \leq 10^{12}
  • 1D1041 \leq D \leq 10^4
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN DD

Output

Print the answer.

Sample Input 1

3 2

Sample Output 1

10

There are 1010 ways, as follows:

Figure

Sample Input 2

299792458 3141

Sample Output 2

138897974

Find the count modulo 998244353998244353.

update @ 2024/3/10 10:54:20