#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
inline int read() {
  static char buf[1000000], *p1 = buf, *p2 = buf;
  register int x = false;
  register char ch =
      p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
          ? EOF
          : *p1++;
  ;
  register bool sgn = false;
  while (ch != '-' && (ch < '0' || ch > '9'))
    ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
             ? EOF
             : *p1++;
  ;
  if (ch == '-')
    sgn = true,
    ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
             ? EOF
             : *p1++;
  ;
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + (ch ^ 48),
    ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
             ? EOF
             : *p1++;
  ;
  return sgn ? -x : x;
}
long long fpow(long long a, long long b, int mod) {
  long long res = 1;
  for (; b > 0; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long a[N];
long long d[N];
int main() {
  long long x, y;
  int cnt = 0;
  cin >> x >> y;
  if (y % x != 0) cout << "0" << endl, exit(0);
  long long k = sqrt(y);
  for (long long i = 1; i <= k; i++) {
    if (y % i == 0) {
      long long u = y / i;
      if (i % x == 0) a[++cnt] = i;
      if (u != i && u % x == 0) a[++cnt] = u;
    }
  }
  sort(a + 1, a + cnt + 1);
  for (int i = cnt; i >= 1; i--) {
    d[i] = fpow(2LL, y / a[i] - 1, mod);
    for (int j = i + 1; j <= cnt; j++) {
      if (a[j] % a[i] == 0) d[i] = (d[i] - d[j] + mod) % mod;
    }
  }
  cout << d[1] << endl;
  return 0;
}
