Count the number of distinct sequences a_1, a_2, ..., a_{n} (1 ≤ a_{i}) consisting of positive integers such that gcd(a_1, a_2, ..., a_{n}) = x and $\sum_{i = 1}^{n} a_{i} = y$. As this number could be large, print the answer modulo 10^9 + 7.

gcd here means the greatest common divisor.


-----Input-----

The only line contains two positive integers x and y (1 ≤ x, y ≤ 10^9).


-----Output-----

Print the number of such sequences modulo 10^9 + 7.


-----Examples-----
Input
3 9

Output
3

Input
5 8

Output
0



-----Note-----

There are three suitable sequences in the first test: (3, 3, 3), (3, 6), (6, 3).

There are no suitable sequences in the second test.

Source: codeforces | Difficulty: HARD
Tags: Bit manipulation

Combinatorics

Number theory

Dynamic programming

Mathematics


Solutions:
mod = 1000000007

def modpow(a, x):
	if x == 0:
		return 1
	if x == 1:
		return a
	b = modpow(a, x // 2)
	return b * b * a ** (x % 2) % mod
import sys
(x, y) = list(map(int, input().split()))
if y % x != 0:
	print(0)
	sys.exit(0)
if x == y:
	print(1)
	sys.exit(0)
a = y // x
divs = []
i = 2
while i * i < a:
	if a % i == 0:
		divs.append(i)
		divs.append(a // i)
	i += 1
if int(a ** 0.5) ** 2 == a:
	divs.append(int(a ** 0.5))
divs.append(a)
divs.sort()
res = modpow(2, a - 1)
muls = [0 for _ in divs]
muls[0] = 1
for (xid, d) in enumerate(divs):
	prevs = 0
	for (id, d2) in enumerate(divs):
		if d2 < d and d % d2 == 0:
			prevs += muls[id]
	muls[xid] = 1 - prevs
	res += (prevs - 1) * modpow(2, a // d - 1)
	res = (res + 1000 * mod) % mod
print(res)


modulo = 10 ** 9 + 7
(num1, num2) = list(map(int, input().split()))
if num2 % num1:
	print('0')
else:
	num2 = num2 // num1
	arr = set()
	for i in range(1, int(pow(num2, 0.5) + 1)):
		if num2 % i == 0:
			arr.add(i)
			arr.add(num2 // i)
	arr = sorted(list(arr))
	cop2 = arr[:]
	for i in range(len(cop2)):
		cop2[i] = pow(2, arr[i] - 1, modulo)
		for j in range(i):
			if arr[i] % arr[j] == 0:
				cop2[i] -= cop2[j]
	print(cop2[-1] % modulo)


from collections import Counter

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def memodict(f):

	class memodict(dict):

		def __missing__(self, key):
			ret = self[key] = f(key)
			return ret
	return memodict().__getitem__

def pollard_rho(n):
	if n & 1 == 0:
		return 2
	if n % 3 == 0:
		return 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			prev = p
			p = p * p % n
			if p == 1:
				return gcd(prev - 1, n)
			if p == n - 1:
				break
		else:
			for i in range(2, n):
				(x, y) = (i, (i * i + 1) % n)
				f = gcd(abs(x - y), n)
				while f == 1:
					(x, y) = ((x * x + 1) % n, (y * y + 1) % n)
					y = (y * y + 1) % n
					f = gcd(abs(x - y), n)
				if f != n:
					return f
	return n

@memodict
def prime_factors(n):
	if n <= 1:
		return Counter()
	f = pollard_rho(n)
	return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f)

def distinct_factors(n):
	factors = [1]
	for (p, exp) in prime_factors(n).items():
		factors += [p ** i * factor for factor in factors for i in range(1, exp + 1)]
	return factors

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	if small[-1] == large[-1]:
		large.pop()
	large.reverse()
	small.extend(large)
	return small
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if not True else 1):
	(x, y) = map(int, input().split())
	if y % x:
		print(0)
		continue
	p = y // x
	factors = all_factors(p)
	di = {}
	for factor in factors:
		val = pow(2, factor - 1, 10 ** 9 + 7)
		for j in factors:
			if j == factor:
				break
			if factor % j == 0:
				val -= di[j]
		di[factor] = val % (10 ** 9 + 7)
	print(di[p])


import math

def UnusualSeq(a, b):
	if b % a != 0:
		print(0)
	else:
		b //= a
		d = set()
		for i in range(1, int(math.sqrt(b) + 1)):
			if b % i == 0:
				d.add(i)
				d.add(b // i)
		d = sorted(list(d))
		f = d[:]
		for i in range(len(f)):
			f[i] = pow(2, d[i] - 1, 10 ** 9 + 7)
			for j in range(i):
				if d[i] % d[j] == 0:
					f[i] -= f[j]
		print(f[-1] % (10 ** 9 + 7))
(a, b) = list(map(int, input().split()))
UnusualSeq(a, b)


import math
mod = 1000000007
(x, y) = [int(x) for x in input().split()]
if y % x != 0:
	print(0)
	exit()
y = y // x
seqs = set()
for x in range(1, int(math.sqrt(y) + 1)):
	if y % x != 0:
		continue
	seqs.add(x)
	seqs.add(y // x)
seqs = sorted(list(seqs))
ordered = seqs.copy()
for i in range(len(seqs)):
	ordered[i] = pow(2, seqs[i] - 1, mod)
	for j in range(i):
		if seqs[i] % seqs[j] == 0:
			ordered[i] -= ordered[j]
print(int(ordered[len(ordered) - 1] % mod))


from fractions import gcd
from operator import mul
from functools import reduce
from itertools import combinations
eval_function = lambda x: lambda f: f(x)

@eval_function(int((10 ** 9) ** 0.5))
def prime(n):
	sieve = [True] * (n + 1)
	sieve[0] = sieve[1] = False
	index = 2
	for i in range(int(len(sieve) ** 0.5)):
		if sieve[i]:
			for j in range(2 * i, len(sieve), i):
				sieve[j] = False
		index += 1
	return [i for (i, is_prime) in enumerate(sieve) if is_prime]

def factorized(n):
	factors = []
	for i in prime:
		if i ** 2 > n:
			break
		while n % i == 0:
			factors += [i]
			n //= i
	if n > 1:
		factors += [n]
	return factors

def count_coprime_parts(n, mod=None):
	count = pow(2, n - 1, mod)
	unique_factors = set(factorized(n))
	for i in range(1, len(unique_factors) + 1):
		for factors in combinations(unique_factors, i):
			d = reduce(mul, factors)
			count += (-1) ** i * pow(2, n // d - 1, mod)
			count %= mod
	return count

def solve(x, y, mod=None):
	if gcd(x, y) != x:
		return 0
	return count_coprime_parts(y // x, mod)

def main():
	(x, y) = [int(n) for n in input().split()]
	print(solve(x, y, 10 ** 9 + 7))

def __starting_point():
	main()
__starting_point()


(x, y) = map(int, input().split())
b = y // x
if y % x != 0:
	print(0)
	return
ds = set()
M = 10 ** 9 + 7
for i in range(1, int(pow(b, 0.5) + 1)):
	if b % i == 0:
		ds.add(i)
		ds.add(b // i)
ds = sorted(list(ds))
ans = pow(2, b - 1, M)
f = ds[:]
for i in range(len(ds)):
	f[i] = pow(2, ds[i] - 1, M)
	for j in range(i):
		if ds[i] % ds[j] == 0:
			f[i] -= f[j]
print(f[-1] % M)


mod = 1000000007
(x, y) = map(int, input().split())
if y % x:
	print(0)
	exit(0)
y //= x
f = {1: 1}

def quick_power(a, b):
	r = 1
	while b:
		if b & 1:
			r = r * a % mod
		a = a * a % mod
		b >>= 1
	return r

def dfs(s):
	if s in f.keys():
		return f[s]
	r = quick_power(2, s - 1)
	for g in range(2, int(s ** 0.5)):
		if s % g == 0:
			r = (r - dfs(s // g) - dfs(g)) % mod
	g = int(s ** 0.5)
	if g >= 2 and s % g == 0:
		if g * g == s:
			r = (r - dfs(g)) % mod
		else:
			r = (r - dfs(s // g) - dfs(g)) % mod
	f[s] = (r - 1) % mod
	return f[s]
print(dfs(y))


import sys
mod = 1000000007

def modpow(a, x):
	if x == 0:
		return 1
	if x == 1:
		return a
	b = modpow(a, x // 2)
	return b * b * a ** (x % 2) % mod
(n, m) = map(int, input().split())
if m % n != 0:
	print(0)
	sys.exit(0)
if n == m:
	print(1)
	sys.exit(0)
ans = m // n
arr = []
i = 2
while i * i < ans:
	if ans % i == 0:
		arr.append(i)
		arr.append(ans // i)
	i += 1
if int(ans ** 0.5) ** 2 == ans:
	arr.append(int(ans ** 0.5))
arr.append(ans)
arr.sort()
result = modpow(2, ans - 1)
muls = [0 for _ in arr]
muls[0] = 1
for (xid, d) in enumerate(arr):
	prevs = 0
	for (id, d2) in enumerate(arr):
		if d2 < d and d % d2 == 0:
			prevs += muls[id]
	muls[xid] = 1 - prevs
	result += (prevs - 1) * modpow(2, ans // d - 1)
	result = (result + 1000 * mod) % mod
print(result)


import sys
mod = 1000000007

def mul(x, y):
	res = 1
	while y > 0:
		if y % 2 == 1:
			res = res * x % mod
		x = x * x % mod
		y //= 2
	return res
(x, y) = map(int, sys.stdin.readline().split())
if y % x != 0:
	print(0)
else:
	y /= x
	d = set([])
	i = 1
	while i * i <= y:
		if y % i == 0:
			d.add(i)
			d.add(y / i)
		i += 1
	d = sorted(list(d))
	dp = d[:]
	for i in range(len(d)):
		dp[i] = mul(2, d[i] - 1)
		for j in range(i):
			if d[i] % d[j] == 0:
				dp[i] -= dp[j]
	print(dp[-1] % mod)


def bin_pow(num, degree, module):
	if degree == 0:
		return 1
	if degree == 1:
		return num % module
	if degree % 2 == 0:
		val = bin_pow(num, degree // 2, module)
		return val * val % module
	return num * bin_pow(num, degree - 1, module) % module
(x, y) = map(int, input().split())
if y % x != 0:
	print(0)
	exit(0)
y //= x
divs = set()
to_gen = []
num = 2
val = y
while num * num <= val:
	degree = 0
	while y % num == 0:
		degree += 1
		y //= num
	if degree != 0:
		to_gen.append((num, degree))
	if num == 2:
		num += 1
	else:
		num += 2
if y != 1:
	to_gen.append((y, 1))
to_gen_len = len(to_gen)

def generate(ind):
	if ind == to_gen_len:
		yield 1
		return
	gen_val = to_gen[ind][0]
	for deg in range(1 + to_gen[ind][1]):
		for each in generate(ind + 1):
			yield (gen_val ** deg * each)
for each in generate(0):
	divs.add(each)
divs = list(divs)
divs.sort()
divs_answers = {}
mod = 10 ** 9 + 7
ans = bin_pow(2, val - 1, mod)
for el in divs:
	if el == 1:
		divs_answers[el] = 1
		ans -= 1
	else:
		curr_val = bin_pow(2, el - 1, mod)
		for other_el in divs:
			if other_el >= el:
				break
			if el % other_el != 0:
				continue
			curr_val -= divs_answers[other_el]
		divs_answers[el] = curr_val % mod
		ans -= curr_val
print(divs_answers[val])


import operator, math, itertools, functools
mod = int(1000000000.0 + 7)

def factor(n):
	a = []
	for i in range(2, int(math.sqrt(n)) + 1):
		while n % i == 0:
			a.append(i)
			n //= i
	if n > 1:
		a.append(n)
	return a

def comp(n):
	f = set(factor(n))
	c = pow(2, n - 1, mod)
	for i in range(1, len(f) + 1):
		if i & 1:
			sign = -1
		else:
			sign = 1
		for j in itertools.combinations(f, i):
			k = functools.reduce(operator.mul, j)
			c += sign * pow(2, n // k - 1, mod)
			c = c % mod
	return c
(x, y) = map(int, input().split())
if y % x == 0:
	print(comp(y // x))
else:
	print(0)


import sys
(x, y) = list(map(int, input().strip().split()))
if y % x != 0:
	print(0)
	return
MOD = 10 ** 9 + 7
K = y // x

def multiply(A, b, MOD):
	(n, m) = (len(A), len(b[0]))
	matrika = [[0 for _ in range(m)] for _ in range(n)]
	for i in range(n):
		for j in range(m):
			vsota = 0
			for k in range(len(A[0])):
				vsota += A[i][k] * b[k][j]
			matrika[i][j] = vsota % MOD
	return matrika

def copy(mat):
	return [e[:] for e in mat]

def fib(n):
	if n == 0:
		return 0
	if n == 1:
		return 1
	if n == 2:
		return 1
	matrika = [[1, 1], [1, 0]]
	pripravi = dict()
	pripravi[1] = copy(matrika)
	s = 1
	pot = [1]
	working = copy(matrika)
	while s <= n:
		working = multiply(working, working, MOD)
		s *= 2
		pripravi[s] = copy(working)
		pot.append(s)
	manjka = n - 2
	pointer = len(pot) - 1
	while manjka > 0:
		if pot[pointer] > manjka:
			pointer -= 1
		else:
			matrika = multiply(matrika, pripravi[pot[pointer]], MOD)
			manjka -= pot[pointer]
	v = [[1], [0]]
	return multiply(matrika, v, MOD)[0][0]
memo2 = dict()

def find(y):
	if y in memo2:
		return memo2[y]
	ALL = pow(2, y - 1, MOD) % MOD
	k = 2
	while k * k <= y:
		if y % k == 0:
			if k * k != y:
				ALL -= find(y // k)
				ALL -= find(k)
			else:
				ALL -= find(k)
		k += 1
	if y != 1:
		ALL -= 1
	memo2[y] = ALL % MOD
	return ALL % MOD
print(find(K) % MOD)

def gcd(x, y):
	if x == 0:
		return y
	if y > x:
		return gcd(y, x)
	if x % y == 0:
		return y
	return gcd(y, x % y)
memo = dict()

def brute(k, gc):
	if (k, gc) in memo:
		return memo[k, gc]
	if k == 0:
		if gc:
			return 1
		else:
			return 0
	ALL = 0
	for i in range(1, k + 1):
		ALL += brute(k - i, gcd(gc, i))
	memo[k, gc] = ALL
	return ALL


MOD = 1000000007
(x, y) = map(int, input().split())
if y % x == 0:
	div = y // x
	y_mult = set()
	for i in range(1, int(pow(div, 0.5) + 1)):
		if div % i == 0:
			y_mult.add(i)
			y_mult.add(div // i)
	y_mult = sorted(list(y_mult))
	ym_copy = y_mult.copy()
	for i in range(len(ym_copy)):
		ym_copy[i] = pow(2, y_mult[i] - 1, MOD)
		for j in range(i):
			if y_mult[i] % y_mult[j] == 0:
				ym_copy[i] -= ym_copy[j]
	print(ym_copy[-1] % MOD)
else:
	print(0)


import math
lectura = lambda : map(int, input().split())
(x, y) = lectura()
mod = 1000000007
if y % x != 0:
	print('0')
else:
	y = y // x
	setPrueba = set()
	for i in range(1, int(math.sqrt(y) + 1)):
		if y % i == 0:
			setPrueba.add(i)
			setPrueba.add(y // i)
	setPrueba = sorted(list(setPrueba))
	setOrdenado = setPrueba.copy()
	for i in range(len(setOrdenado)):
		setOrdenado[i] = pow(2, setPrueba[i] - 1, mod)
		for j in range(i):
			if setPrueba[i] % setPrueba[j] == 0:
				setOrdenado[i] -= setOrdenado[j]
	print(setOrdenado[len(setOrdenado) - 1] % mod)


from collections import defaultdict
(x, y) = map(int, input().split())
if y % x != 0:
	print(0)
	exit()
x = y // x
divisors = []
for i in range(1, int(x ** 0.5) + 1):
	if x % i == 0:
		divisors.append(i)
		divisors.append(x // i)
if divisors[-1] == divisors[-2]:
	divisors.pop()
divisors.sort()
va = defaultdict(int)
va[1] = 1
mod = 10 ** 9 + 7
for i in range(1, len(divisors)):
	k = divisors[i]
	count = pow(2, k - 1, mod)
	for j in range(i):
		if k % divisors[j] == 0:
			count = (count - va[divisors[j]]) % mod
	va[k] = count
print(va[x])


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=300006, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.height = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val == 0:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
			elif val >= 1:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left

	def do(self, temp):
		if not temp:
			return 0
		ter = temp
		temp.height = self.do(ter.left) + self.do(ter.right)
		if temp.height == 0:
			temp.height += 1
		return temp.height

	def query(self, xor):
		self.temp = self.root
		cur = 0
		i = 31
		while i > -1:
			val = xor & 1 << i
			if not self.temp:
				return cur
			if val >= 1:
				self.opp = self.temp.right
				if self.temp.left:
					self.temp = self.temp.left
				else:
					return cur
			else:
				self.opp = self.temp.left
				if self.temp.right:
					self.temp = self.temp.right
				else:
					return cur
			if self.temp.height == pow(2, i):
				cur += 1 << i
				self.temp = self.opp
			i -= 1
		return cur
(x, y) = map(int, input().split())
if y % x != 0:
	print(0)
	sys.exit(0)
y //= x
d = defaultdict(int)

def calc(y):
	if y == 1:
		d[1] = 1
		return 1
	if d[y] != 0:
		return d[y]
	else:
		ans = 0
		for i in range(1, int(math.sqrt(y)) + 1):
			if y % i == 0:
				ans -= calc(i)
				ans %= mod
				if i != 1 and y // i != i:
					ans -= calc(y // i)
					ans %= mod
		ans += pow(2, y - 1, mod)
		d[y] = ans % mod
		return d[y]
print(calc(y))


p = 1000000007

def mul(x, y):
	rt = 1
	while y > 0:
		if y % 2 == 1:
			rt = rt * x % p
		x = x * x % p
		y = y // 2
	return rt
(x, y) = map(int, input().split())
if y % x != 0:
	print(0)
else:
	y /= x
	d = set([])
	i = 1
	while i * i <= y:
		if y % i == 0:
			d.add(i)
			d.add(y / i)
		i += 1
	d = sorted(list(d))
	dp = d[:]
	for i in range(len(d)):
		dp[i] = mul(2, d[i] - 1)
		for j in range(i):
			if d[i] % d[j] == 0:
				dp[i] -= dp[j]
	print(dp[-1] % p)


import os
import sys
import math
from io import BytesIO, IOBase
import io
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
from collections import Counter
import threading
BUFSIZE = 8192

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(10001)]
prime[0] = prime[1] = False

def SieveOfEratosthenes(n=10000):
	p = 2
	c = 0
	while p <= n:
		if prime[p] == True:
			c += 1
			for i in range(p, n + 1, p):
				prime[i] = False
		p += 1

class DSU:

	def __init__(self, R, C):
		self.par = range(R * C + 1)
		self.rnk = [0] * (R * C + 1)
		self.sz = [1] * (R * C + 1)

	def find(self, x):
		if self.par[x] != x:
			self.par[x] = self.find(self.par[x])
		return self.par[x]

	def union(self, x, y):
		(xr, yr) = (self.find(x), self.find(y))
		if xr == yr:
			return
		if self.rnk[xr] < self.rnk[yr]:
			(xr, yr) = (yr, xr)
		if self.rnk[xr] == self.rnk[yr]:
			self.rnk[xr] += 1
		self.par[yr] = xr
		self.sz[xr] += self.sz[yr]

	def size(self, x):
		return self.sz[self.find(x)]

	def top(self):
		return self.size(len(self.sz) - 1) - 1

class LazySegTree:

	def __init__(self, _op, _e, _mapping, _composition, _id, v):

		def set(p, x):
			assert 0 <= p < _n
			p += _size
			for i in range(_log, 0, -1):
				_push(p >> i)
			_d[p] = x
			for i in range(1, _log + 1):
				_update(p >> i)

		def get(p):
			assert 0 <= p < _n
			p += _size
			for i in range(_log, 0, -1):
				_push(p >> i)
			return _d[p]

		def prod(l, r):
			assert 0 <= l <= r <= _n
			if l == r:
				return _e
			l += _size
			r += _size
			for i in range(_log, 0, -1):
				if l >> i << i != l:
					_push(l >> i)
				if r >> i << i != r:
					_push(r >> i)
			sml = _e
			smr = _e
			while l < r:
				if l & 1:
					sml = _op(sml, _d[l])
					l += 1
				if r & 1:
					r -= 1
					smr = _op(_d[r], smr)
				l >>= 1
				r >>= 1
			return _op(sml, smr)

		def apply(l, r, f):
			assert 0 <= l <= r <= _n
			if l == r:
				return
			l += _size
			r += _size
			for i in range(_log, 0, -1):
				if l >> i << i != l:
					_push(l >> i)
				if r >> i << i != r:
					_push(r - 1 >> i)
			l2 = l
			r2 = r
			while l < r:
				if l & 1:
					_all_apply(l, f)
					l += 1
				if r & 1:
					r -= 1
					_all_apply(r, f)
				l >>= 1
				r >>= 1
			l = l2
			r = r2
			for i in range(1, _log + 1):
				if l >> i << i != l:
					_update(l >> i)
				if r >> i << i != r:
					_update(r - 1 >> i)

		def _update(k):
			_d[k] = _op(_d[2 * k], _d[2 * k + 1])

		def _all_apply(k, f):
			_d[k] = _mapping(f, _d[k])
			if k < _size:
				_lz[k] = _composition(f, _lz[k])

		def _push(k):
			_all_apply(2 * k, _lz[k])
			_all_apply(2 * k + 1, _lz[k])
			_lz[k] = _id
		_n = len(v)
		_log = _n.bit_length()
		_size = 1 << _log
		_d = [_e] * (2 * _size)
		_lz = [_id] * _size
		for i in range(_n):
			_d[_size + i] = v[i]
		for i in range(_size - 1, 0, -1):
			_update(i)
		self.set = set
		self.get = get
		self.prod = prod
		self.apply = apply
MIL = 1 << 20

def makeNode(total, count):
	return total * MIL + count

def getTotal(node):
	return math.floor(node / MIL)

def getCount(node):
	return node - getTotal(node) * MIL
nodeIdentity = makeNode(0.0, 0.0)

def nodeOp(node1, node2):
	return node1 + node2
	return makeNode(getTotal(node1) + getTotal(node2), getCount(node1) + getCount(node2))
identityMapping = -1

def mapping(tag, node):
	if tag == identityMapping:
		return node
	count = getCount(node)
	return makeNode(tag * count, count)

def composition(mapping1, mapping2):
	return mapping1 if mapping1 != identityMapping else mapping2

def memodict(f):

	class memodict(dict):

		def __missing__(self, key):
			ret = self[key] = f(key)
			return ret
	return memodict().__getitem__

def pollard_rho(n):
	if n & 1 == 0:
		return 2
	if n % 3 == 0:
		return 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			prev = p
			p = p * p % n
			if p == 1:
				return math.gcd(prev - 1, n)
			if p == n - 1:
				break
		else:
			for i in range(2, n):
				(x, y) = (i, (i * i + 1) % n)
				f = math.gcd(abs(x - y), n)
				while f == 1:
					(x, y) = ((x * x + 1) % n, (y * y + 1) % n)
					y = (y * y + 1) % n
					f = math.gcd(abs(x - y), n)
				if f != n:
					return f
	return n

@memodict
def prime_factors(n):
	if n <= 1:
		return Counter()
	f = pollard_rho(n)
	return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f)

def distinct_factors(n):
	factors = [1]
	for (p, exp) in prime_factors(n).items():
		factors += [p ** i * factor for factor in factors for i in range(1, exp + 1)]
	return factors

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	if small[-1] == large[-1]:
		large.pop()
	large.reverse()
	small.extend(large)
	return small

def binarySearch(arr, n, i, key):
	left = 0
	right = n - 1
	mid = 0
	res = n
	while left <= right:
		mid = (right + left) // 2
		if arr[mid][i] > key:
			res = mid
			right = mid - 1
		else:
			left = mid + 1
	return res

def binarySearch1(arr, n, i, key):
	left = 0
	right = n - 1
	mid = 0
	res = -1
	while left <= right:
		mid = (right + left) // 2
		if arr[mid][i] > key:
			right = mid - 1
		else:
			res = mid
			left = mid + 1
	return res
import os
import sys
import math
from io import BytesIO, IOBase
import io
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
from collections import Counter
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(10001)]
prime[0] = prime[1] = False

def SieveOfEratosthenes(n=10000):
	p = 2
	c = 0
	while p <= n:
		if prime[p] == True:
			c += 1
			for i in range(p, n + 1, p):
				prime[i] = False
		p += 1

class DSU:

	def __init__(self, R, C):
		self.par = range(R * C + 1)
		self.rnk = [0] * (R * C + 1)
		self.sz = [1] * (R * C + 1)

	def find(self, x):
		if self.par[x] != x:
			self.par[x] = self.find(self.par[x])
		return self.par[x]

	def union(self, x, y):
		(xr, yr) = (self.find(x), self.find(y))
		if xr == yr:
			return
		if self.rnk[xr] < self.rnk[yr]:
			(xr, yr) = (yr, xr)
		if self.rnk[xr] == self.rnk[yr]:
			self.rnk[xr] += 1
		self.par[yr] = xr
		self.sz[xr] += self.sz[yr]

	def size(self, x):
		return self.sz[self.find(x)]

	def top(self):
		return self.size(len(self.sz) - 1) - 1

class LazySegTree:

	def __init__(self, _op, _e, _mapping, _composition, _id, v):

		def set(p, x):
			assert 0 <= p < _n
			p += _size
			for i in range(_log, 0, -1):
				_push(p >> i)
			_d[p] = x
			for i in range(1, _log + 1):
				_update(p >> i)

		def get(p):
			assert 0 <= p < _n
			p += _size
			for i in range(_log, 0, -1):
				_push(p >> i)
			return _d[p]

		def prod(l, r):
			assert 0 <= l <= r <= _n
			if l == r:
				return _e
			l += _size
			r += _size
			for i in range(_log, 0, -1):
				if l >> i << i != l:
					_push(l >> i)
				if r >> i << i != r:
					_push(r >> i)
			sml = _e
			smr = _e
			while l < r:
				if l & 1:
					sml = _op(sml, _d[l])
					l += 1
				if r & 1:
					r -= 1
					smr = _op(_d[r], smr)
				l >>= 1
				r >>= 1
			return _op(sml, smr)

		def apply(l, r, f):
			assert 0 <= l <= r <= _n
			if l == r:
				return
			l += _size
			r += _size
			for i in range(_log, 0, -1):
				if l >> i << i != l:
					_push(l >> i)
				if r >> i << i != r:
					_push(r - 1 >> i)
			l2 = l
			r2 = r
			while l < r:
				if l & 1:
					_all_apply(l, f)
					l += 1
				if r & 1:
					r -= 1
					_all_apply(r, f)
				l >>= 1
				r >>= 1
			l = l2
			r = r2
			for i in range(1, _log + 1):
				if l >> i << i != l:
					_update(l >> i)
				if r >> i << i != r:
					_update(r - 1 >> i)

		def _update(k):
			_d[k] = _op(_d[2 * k], _d[2 * k + 1])

		def _all_apply(k, f):
			_d[k] = _mapping(f, _d[k])
			if k < _size:
				_lz[k] = _composition(f, _lz[k])

		def _push(k):
			_all_apply(2 * k, _lz[k])
			_all_apply(2 * k + 1, _lz[k])
			_lz[k] = _id
		_n = len(v)
		_log = _n.bit_length()
		_size = 1 << _log
		_d = [_e] * (2 * _size)
		_lz = [_id] * _size
		for i in range(_n):
			_d[_size + i] = v[i]
		for i in range(_size - 1, 0, -1):
			_update(i)
		self.set = set
		self.get = get
		self.prod = prod
		self.apply = apply
MIL = 1 << 20

def makeNode(total, count):
	return total * MIL + count

def getTotal(node):
	return math.floor(node / MIL)

def getCount(node):
	return node - getTotal(node) * MIL
nodeIdentity = makeNode(0.0, 0.0)

def nodeOp(node1, node2):
	return node1 + node2
	return makeNode(getTotal(node1) + getTotal(node2), getCount(node1) + getCount(node2))
identityMapping = -1

def mapping(tag, node):
	if tag == identityMapping:
		return node
	count = getCount(node)
	return makeNode(tag * count, count)

def composition(mapping1, mapping2):
	return mapping1 if mapping1 != identityMapping else mapping2

def memodict(f):

	class memodict(dict):

		def __missing__(self, key):
			ret = self[key] = f(key)
			return ret
	return memodict().__getitem__

def pollard_rho(n):
	if n & 1 == 0:
		return 2
	if n % 3 == 0:
		return 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			prev = p
			p = p * p % n
			if p == 1:
				return math.gcd(prev - 1, n)
			if p == n - 1:
				break
		else:
			for i in range(2, n):
				(x, y) = (i, (i * i + 1) % n)
				f = math.gcd(abs(x - y), n)
				while f == 1:
					(x, y) = ((x * x + 1) % n, (y * y + 1) % n)
					y = (y * y + 1) % n
					f = math.gcd(abs(x - y), n)
				if f != n:
					return f
	return n

@memodict
def prime_factors(n):
	if n <= 1:
		return Counter()
	f = pollard_rho(n)
	return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f)

def distinct_factors(n):
	factors = [1]
	for (p, exp) in prime_factors(n).items():
		factors += [p ** i * factor for factor in factors for i in range(1, exp + 1)]
	return factors

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	if small[-1] == large[-1]:
		large.pop()
	large.reverse()
	small.extend(large)
	return small

def binarySearch(arr, n, i, key):
	left = 0
	right = n - 1
	mid = 0
	res = n
	while left <= right:
		mid = (right + left) // 2
		if arr[mid][i] > key:
			res = mid
			right = mid - 1
		else:
			left = mid + 1
	return res

def binarySearch1(arr, n, i, key):
	left = 0
	right = n - 1
	mid = 0
	res = -1
	while left <= right:
		mid = (right + left) // 2
		if arr[mid][i] > key:
			right = mid - 1
		else:
			res = mid
			left = mid + 1
	return res
modulo = 10 ** 9 + 7
(num1, num2) = map(int, input().split())
if num2 % num1:
	print('0')
else:
	num2 = num2 // num1
	arr = set()
	for i in range(1, int(pow(num2, 0.5) + 1)):
		if num2 % i == 0:
			arr.add(i)
			arr.add(num2 // i)
	arr = sorted(list(arr))
	cop2 = arr[:]
	for i in range(len(cop2)):
		cop2[i] = pow(2, arr[i] - 1, modulo)
		for j in range(i):
			if arr[i] % arr[j] == 0:
				cop2[i] -= cop2[j]
	print(cop2[-1] % modulo)


M = 10 ** 9 + 7
(a, b) = list(map(int, input().split()))
if b % a:
	print(0)
else:
	b //= a
	d = set()
	for i in range(1, int(pow(b, 0.5) + 1)):
		if b % i == 0:
			d.add(i)
			d.add(b // i)
	d = sorted(list(d))
	f = d[:]
	for i in range(len(f)):
		f[i] = pow(2, d[i] - 1, M)
		for j in range(i):
			if d[i] % d[j] == 0:
				f[i] -= f[j]
	print(f[-1] % M)


from __future__ import division, print_function
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange

def sync_with_stdio(b):
	if b:
		return
	import os, sys
	from io import BytesIO, IOBase

	class FastI(object):

		def __init__(self, fd=0, buffersize=2 ** 14):
			self.stream = stream = BytesIO()
			self.bufendl = 0

			def read2buffer():
				s = os.read(fd, buffersize + os.fstat(fd).st_size)
				pos = stream.tell()
				stream.seek(0, 2)
				stream.write(s)
				stream.seek(pos)
				return s
			self.read2buffer = read2buffer

		def read(self):
			while self.read2buffer():
				pass
			return self.stream.read() if self.stream.tell() else self.stream.getvalue()

		def readline(self):
			while self.bufendl == 0:
				s = self.read2buffer()
				self.bufendl += s.count(b'\n') + (not s)
			self.bufendl -= 1
			return self.stream.readline()

		def input(self):
			return self.readline().rstrip(b'\r\n')

		def readnumbers(self, zero=0):
			conv = ord if py2 else lambda x: x
			A = []
			numb = zero
			sign = 1
			c = b'-'[0]
			for c in self.read():
				if c >= b'0'[0]:
					numb = 10 * numb + conv(c) - 48
				elif c == b'-'[0]:
					sign = -1
				elif c != b'\r'[0]:
					A.append(sign * numb)
					numb = zero
					sign = 1
			if c >= b'0'[0]:
				A.append(sign * numb)
			return A

	class FastO(IOBase):

		def __init__(self, fd=1):
			stream = BytesIO()
			self.flush = lambda : os.write(1, stream.getvalue()) and (not stream.truncate(0)) and stream.seek(0)
			self.write = stream.write if py2 else lambda s: stream.write(s.encode())
	(sys.stdin, sys.stdout) = (FastI(), FastO())
	global input
	input = sys.stdin.input
import sys

class ostream:

	def __lshift__(self, a):
		if a == endl:
			sys.stdout.write('\n')
			sys.stdout.flush()
		else:
			sys.stdout.write(str(a))
		return self

	def tie(self, val):
		pass
cout = ostream()
endl = object()

class istream:
	tiedto = cout
	inp = None

	def __rlshift__(a, b):
		if a.tiedto == cout:
			sys.stdout.flush()
		if type(b) == tuple or type(b) == list:
			return type(b)((type(c)(a.get()) for c in b))
		return type(b)(a.get())

	def tie(self, val):
		self.tiedto = val

	def get(a):
		while not a.inp:
			a.inp = sys.stdin.readline().split()[::-1]
		return a.inp.pop()
cin = istream()

class Vector:

	def __lshift__(self, other):
		self.type = other
		return self

	def __rshift__(self, other):
		if type(other) == tuple:
			return [self.type(other[1])] * other[0]
		else:
			return [self.type()] * other
vector = Vector()
sync_with_stdio(False)
cin.tie(0)
cout.tie(0)
MOD = 10 ** 9 + 7
x = 0
y = 0
x <<= cin
y <<= cin
mem = {}

def ways(summa):
	if summa not in mem:
		c = pow(2, summa - 1, MOD) - 1
		i = 2
		while i * i < summa:
			if summa % i == 0:
				c = (c - ways(i)) % MOD
			i += 1
		if i * i == summa:
			c = (c - ways(i)) % MOD
		i -= 1
		while i > 1:
			if summa % i == 0:
				c = (c - ways(summa // i)) % MOD
			i -= 1
		mem[summa] = c
	return mem[summa]
mem[0] = 0
mem[1] = 1
ans = ways(y // x) if y % x == 0 else 0
cout << ans << endl


lista = input().split(' ')

def prueba(f, *params):
	i = 1
	for a in params:
		if f(a[0], a[1]) != a[2]:
			print('El caso', i, 'es incorrecto se respondio', f(a[0], a[1]), 'y se esperaba', a[2])
		else:
			print('El caso', i, 'es correcto')
		i += 1

def comparacion(f, g, *casos):
	for a in casos:
		print('La primera responde', f(a[0], a[1]), 'y la segunda funcion responde', g(a[0], a[1]))

def gcd(a, b):
	if a < b:
		return gcd(b, a)
	if b == 0:
		return a
	resto = a % b
	if resto > b // 2:
		return gcd(b, b - resto)
	else:
		return gcd(b, resto)

def Unusual2(x, y):
	a = set()
	o = 10 ** 9 + 7
	if y < x or y % x != 0:
		return 0
	y //= x
	for i in range(1, int(pow(y, 0.5) + 1)):
		if y % i == 0:
			a.add(i)
			a.add(y // i)
	lista = sorted(list(a))
	copia = lista[:]
	for i in range(len(lista)):
		copia[i] = int(pow(2, lista[i] - 1, o))
		for j in range(i):
			if lista[i] % lista[j] == 0:
				copia[i] -= copia[j]
	return copia[len(copia) - 1] % o
print(Unusual2(int(lista[0]), int(lista[1])))