PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000344. Đếm bộ ba bội số có XOR bằng 0 (Nim)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đếm bộ ba bội số có XOR bằng 0 (Nim)

Nim

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Given integers N,A1,A2,A3N,A_1,A_2,A_3, count ordered triples of positive integers (X1,X2,X3)(X_1,X_2,X_3) satisfying all conditions:

  • 1≤Xi≤N1\le X_i\le N for all i∈{1,2,3}i\in\{1,2,3\}.
  • AiA_i divides XiX_i for all i∈{1,2,3}i\in\{1,2,3\}.
  • X1⊕X2⊕X3=0X_1\oplus X_2\oplus X_3=0, where ⊕\oplus denotes bitwise XOR.

Print the answer modulo 998244353998244353. The positions of the values matter.

Input

One line containing N,A1,A2,A3N,A_1,A_2,A_3.

Output

Print the count of valid triples modulo 998244353998244353.

Subtasks

  • Subtask 1 (20 points): 1≤N≤601\le N\le 60, 1≤A1,A2,A3≤101\le A_1,A_2,A_3\le10.
  • Subtask 2 (30 points): 1≤N≤1061\le N\le 10^6, 1≤A1,A2,A3≤101\le A_1,A_2,A_3\le10.
  • Subtask 3 (50 points): 1≤N≤10181\le N\le 10^{18}, 1≤A1,A2,A3≤101\le A_1,A_2,A_3\le10.

Examples

Example 1

Input

13 2 3 5

Output

4

Explanation

The four valid triples are (6,3,5)(6,3,5), (6,12,10)(6,12,10), (12,6,10)(12,6,10), and (12,9,5)(12,9,5); each satisfies the divisibility and XOR requirements.

Example 2

Input

1000000000000000000 1 1 1

Output

426724011

Explanation

This maximum-bound case requires bitwise digit DP instead of enumeration. The result is reduced modulo 998244353998244353.