#P2231. [HNOI2002] 跳蚤

    ID: 1205 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2002各省省选数论湖南最大公约数,gcd不定方程莫比乌斯反演

[HNOI2002] 跳蚤

Description

Many fleas live in Z City. There is an entertainment show on the Saturday Life channel in Z City. A flea will be placed at the exact middle of a high wire. The wire is very long and can be regarded as infinite. The host will give the flea a card. The card has N+1N+1 positive integers. The last one is MM, and each of the first NN numbers does not exceed MM. Duplicate numbers are allowed on the card. Each time, the flea can choose any positive integer SS from the card and then jump SS units either to the left or to the right. Its task is to end up at the point located one unit to its left and pick up the gift there.

For example, when N=2,M=18N=2, M=18, a flea holding the card (10,15,18)(10, 15, 18) can complete the task: it can first jump 1010 units to the left, then jump left 33 more times, 1515 units each time, and finally jump right 33 times, 1818 units each time. However, with the card (12,15,18)(12, 15, 18), it is impossible to reach the point one unit to its left.

When NN and MM are fixed, there are clearly MNM^N different cards. The question is: among all these cards, how many of them can complete the task?

Input Format

The input consists of a single line with two integers NN and MM separated by a space.

Output Format

Output a single line containing the number of cards that can complete the task.

Constraints

1NM1081 \le N \le M \le 10^8, and MN1016M^N \le 10^{16}.

2 4
12

Hint

These 12 cards are:

$(1, 1, 4), (1, 2, 4), (1, 3, 4), (1, 4, 4), (2, 1, 4), (2, 3, 4)$

$(3, 1, 4), (3, 2, 4), (3, 3, 4), (3, 4, 4), (4, 1, 4), (4, 3, 4)$

Translated by ChatGPT 5