Under construction

Still being built. Things may change

GCD and Shortest Path

Time limit1sMemory limit1024 MB

Summary
Count the vertices x from 1 to N whose shortest-path distance to K in the coprime graph equals gcd(x, K).
Level

Medium7 of 10

Topics
Number theory, Graph, Math
Solved
No attempts yet

Problem

\newcommand{\dist}{\mathrm{dist}}

A graph with NN vertices, numbered from 11 to NN, is given. The graph has the following property.

For two distinct integers x,yx, y that satisfy 1≤x,y≤N1 \leq x, y \leq N:

  • If gcd⁡(x,y)=1\gcd(x, y) = 1, an edge connects vertex xx and vertex yy.
  • If gcd⁡(x,y)≠1\gcd(x, y) \neq 1, no edge connects vertex xx and vertex yy.

Define \dist(x,y)\dist(x, y) as the length of the shortest path between vertex xx and vertex yy. If no path connects the two vertices, define \dist(x,y)=101010\dist(x, y) = 10^{10^{10}}. By definition, \dist(x,x)=0\dist(x, x) = 0.

Given an integer KK with 1≤K≤N1 \leq K \leq N, count the integers xx with 1≤x≤N1 \leq x \leq N that satisfy \dist(x,K)=gcd⁡(x,K)\dist(x, K) = \gcd(x, K).

Input

Print the first line with the integer KK and the integer NN, separated by a space. (1≤K≤N≤1061 \leq K \leq N \leq 10^6)

Output

On the first line, print the number of integers that satisfy the condition.

Hint

gcd⁡(x,y)\gcd(x, y) is the greatest common divisor of xx and yy.

The length of a path is the number of edges it contains. The length of the shortest path is the minimum of these lengths.

Examples4

  1. Example 1

    Input
    3 4
    
    Expected output
    3
    
  2. Example 2

    Input
    6 20
    
    Expected output
    14
    
  3. Example 3

    Input
    2 3
    
    Expected output
    2
    
  4. Example 4

    Input
    1 1
    
    Expected output
    0