Number Sets

Count the connected components formed when numbers A through B are merged whenever they share a prime factor at least P.

Medium7Union-findNumber theoryMathNo attempts yetTime limit2sMemory limit512 MB

Problem

The consecutive natural numbers from AA to BB are given. Alice wants to group them into sets.

The sets are built as follows.

  • At the start, make one set of size 1 for each number.
  • For every pair (x,y)(x, y) of numbers in the range, if xx and yy have a common prime factor that is at least PP, merge the set containing xx with the set containing yy.

For example, take P=3P = 3, A=3A = 3, B=15B = 15. The sets are {3,5,6,9,10,12,15}\{3, 5, 6, 9, 10, 12, 15\}, {4}\{4\}, {7,14}\{7, 14\}, {8}\{8\}, {11}\{11\}, {13}\{13\}, so the number of sets is 6.

Given AA, BB, and PP, find how many sets this procedure produces.

Input

The first line contains AA, BB, and PP separated by spaces. (1AB10121 \le A \le B \le 10^{12}, BA+106B \le A + 10^6, 2PB2 \le P \le B)

Output

Print the number of sets produced by the rule above.