This page is still under construction.

Parts of this page are still being built. What you see may change.

Number Sets

Time limit2sMemory limit512 MB

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

Medium7 of 10

Topics
Union-find, Number theory, Math
Solved
No attempts yet

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. (1≤A≤B≤10121 \le A \le B \le 10^{12}, B≤A+106B \le A + 10^6, 2≤P≤B2 \le P \le B)

Output

Print the number of sets produced by the rule above.

Examples3

  1. Example 1

    Input
    3 15 3
    
    Expected output
    6
    
  2. Example 2

    Input
    10 20 5
    
    Expected output
    9
    
  3. Example 3

    Input
    10 20 3
    
    Expected output
    7