Under construction

Still being built. Things may change

Linear Congruences

Time limit1sMemory limit512 MB

Summary
Given M and b, count pairs (a, m) with 1 <= a <= M and 2 <= m <= M where ax = b (mod m) has at least one solution.
Level

Medium6 of 10

Topics
Number theory, Math, Divide and conquer
Solved
No attempts yet

Problem

Given integers MM and bb, write a program that counts the pairs (a,m)(a, m) that satisfy both conditions below.

  • Condition 1: aa and mm are integers with 1≤a≤M1 \le a \le M and 2≤m≤M2 \le m \le M, respectively.
  • Condition 2: the linear congruence ax≡b(modm)ax \equiv b \pmod m in xx has at least one solution.

Input

The first line contains integers MM and bb in this order.

Output

Print the number of pairs (a,m)(a, m) that satisfy the conditions.

Constraints

  • 2≤M≤2×1052 \le M \le 2 \times 10^5
  • 0≤b≤10120 \le b \le 10^{12}
  • All numbers in the input are integers.

Examples2

  1. Example 1

    Input
    3 4
    
    Expected output
    5
    
  2. Example 2

    Input
    5 7
    
    Expected output
    14