Fermat's Theorem#3247

Fermat's Theorem

0.5 seconds
64 megabytes
Medium

...everything was composed in the distant Middle Ages — and modern authors only steal from it. Medieval writers, in turn, stole these thoughts from the ancients, and if something new flashed in their works — this means that the sources have not been preserved and have not come down to us.

J. Huberman

Probably there is no person in the world who has not heard of Fermat's Last Theorem. It has a unique history, which perhaps no other theorem in the world has, and the world's best minds fought over it for years until it was proved by the American mathematician Andrew Wiles. The statement of the theorem is quite simple: for every integer k > 2, the equation

a^k + b^k = c^k

has no positive integer solutions , and . To be precise, Fermat wrote in the margins of Diophantus' book 'Arithmetic': "It is impossible to decompose a cube into two cubes, or a fourth power into two fourth powers, or in general, any power higher than the second into two like powers. I have discovered a truly marvelous proof of this, but these margins are too narrow to contain it." In this task, you certainly do not have to prove this theorem, you only need to determine for a given natural number the number of ways it can be represented as the sum of two powers of natural numbers with exponent . In other words, how many unordered pairs of natural numbers satisfy the equation:

x^k + y^k = n

Input

The input file contains a pair of numbers , (1 \leq n \leq 10^{18}, 1 \leq k \leq 100).

Output

Output a single number — the number of solutions.

Examples

Example 1

Loading
Loading