#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long x, y;
std::vector<int> divisors;
map<int, int> memo;
long long mulmod(long long a, long long b, long long c) {
  a %= c;
  b %= c;
  return (a * b) % c;
}
long long exp(long long a, long long b, long long c) {
  long long x = 1, y = a;
  while (b > 0) {
    if (b % 2 == 1) x = mulmod(x, y, c);
    y = mulmod(y, y, c);
    b /= 2;
  }
  return x % c;
}
long long f(long long n) {
  if (n == 0)
    return 0;
  else if (n == 1)
    return 1;
  else if (memo[n])
    return memo[n];
  long long ans = exp(2, n - 1, mod);
  for (long long i : divisors) {
    if (i > n) break;
    if (n % i == 0) ans = (ans - f(n / i) + mod) % mod;
  }
  return memo[n] = ans;
}
int main() {
  cin >> x >> y;
  int val = y % x;
  if (val) {
    cout << 0;
    return 0;
  }
  long long g = y / x;
  for (int i = 2; i * i <= g; i++) {
    if (g % i == 0) {
      divisors.emplace_back(i);
      if (g / i != i) divisors.emplace_back(g / i);
    }
  }
  sort(divisors.begin(), divisors.end());
  cout << f(g) - ((x == y) ? 0 : 1) << '\n';
}
