#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30);
const int maxn = (100005);
inline long long Read() {
  char ch = getchar();
  long long u = 0, f = 1;
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    u = u * 10 + ch - 48;
    ch = getchar();
  }
  return u * f;
}
int n, m;
inline void Init() { n = Read(), m = Read(); }
const int mod = (1e9 + 7);
inline long long Mod(long long x) {
  while (x >= mod) x -= mod;
  while (x < 0) x += mod;
  return x;
}
long long pow(long long x, long long y) {
  long long rtn = 1;
  for (; y; y >>= 1, x = (x * x) % mod)
    if (y & 1) rtn = (rtn * x) % mod;
  return Mod(rtn);
}
vector<long long> q;
long long F[15000];
void Work(long long x) {
  F[1] = 1;
  F[2] = 1;
  for (register int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      q.push_back(i);
      if (x / i != i) q.push_back(x / i);
    }
  }
  q.push_back(1);
  if (x != 1) q.push_back(x);
  sort(q.begin(), q.end());
  for (register int i = 0; i < q.size(); i++) {
    long long ans = pow(2ll, q[i] - 1);
    for (int j = 0; j < i; j++)
      if (q[i] % q[j] == 0) ans = (ans - F[j] + mod) % mod;
    F[i] = ans % mod;
  }
  printf("%lld\n", F[q.size() - 1]);
}
inline void Solve() {
  if (m % n != 0)
    exit(0 * printf("0"));
  else {
    Work(m / n);
  }
}
int main() {
  Init();
  Solve();
  return 0;
}
