[Solution] Power Board solution codeforces

Power Board solution codeforces – You have a rectangular board of size 𝑛×𝑚n×m (𝑛n rows, 𝑚m columns). The 𝑛n rows are numbered from 11 to 𝑛n from top to bottom, and the 𝑚m columns are numbered from 11 to 𝑚m from left to right.

The cell at the intersection of row 𝑖i and column 𝑗j contains the number 𝑖𝑗ij (𝑖i raised to the power of 𝑗j). For example, if 𝑛=3n=3 and 𝑚=3m=3 the board is as follows:

Power Board solution codeforces
Find the number of distinct integers written on the board.

Power Board solution codeforces

The only line contains two integers 𝑛n and 𝑚m (1𝑛,𝑚1061≤n,m≤106) — the number of rows and columns of the board.

Output

Print one integer, the number of distinct integers on the board.

Examples
input

Copy
3 3
output

Copy
7

Power Board solution codeforces

2 4
output

Copy
5
input

Copy
4 2
output

Copy
6

Power Board solution codeforces

The statement shows the board for the first test case. In this case there are 77 distinct integers: 112233448899, and 2727.

In the second test case, the board is as follows:

There are 55 distinct numbers: 11224488 and 1616.

In the third test case, the board is as follows:

There are 66 distinct numbers: 1122334499 and 1616.

Leave a Comment