#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1000005;
const long long dd = (long long)(1e9) + 7;
long long n, t;
long long sum[maxn];
bool p[maxn];
map<long long, long long> mem;
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
inline long long read() {
  long long ret = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (isdigit(ch)) {
    ret = ret * 10 + ch - '0';
    ch = getchar();
  }
  return ret * f;
}
long long qpow(long long x, long long p) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans = ans * x % dd;
    p >>= 1;
    x = x * x % dd;
  }
  return ans;
}
long long mu(long long n) {
  long long ans = 1, sum = 1, m = n;
  for (long long k = 2; k * k <= n; k++) {
    if (n % k) continue;
    if (gcd(k, sum) > 1) continue;
    sum *= k;
    while (!(m % k)) m /= k;
    if (n % (k * k))
      ans = -ans;
    else
      return 0;
  }
  if (m > 1) ans = -ans;
  return ans;
}
void solve() {
  long long x, y;
  x = read();
  y = read();
  if (y % x) {
    puts("0");
    return;
  }
  n = y / x;
  long long ans = 0;
  for (long long k = 1; k * k <= n; k++)
    if (!(n % k)) {
      long long j = n / k;
      ans += qpow(2, j - 1) * mu(k);
      if (k == j) continue;
      ans += qpow(2, k - 1) * mu(j);
      ans %= dd;
    }
  ans += dd;
  ans %= dd;
  printf("%lld\n", ans);
}
signed main() {
  solve();
  return 0;
}
