#include <bits/stdc++.h>
using namespace std;
using cd = complex<double>;
const double PI = acos(-1);
void fft(vector<cd>& a, bool invert) {
  int n = a.size();
  if (n == 1) return;
  vector<cd> a0(n / 2), a1(n / 2);
  for (int i = 0; 2 * i < n; i++) {
    a0[i] = a[2 * i];
    a1[i] = a[2 * i + 1];
  }
  fft(a0, invert);
  fft(a1, invert);
  double ang = 2 * PI / n * (invert ? -1 : 1);
  cd w(1), wn(cos(ang), sin(ang));
  for (int i = 0; 2 * i < n; i++) {
    a[i] = a0[i] + w * a1[i];
    a[i + n / 2] = a0[i] - w * a1[i];
    if (invert) {
      a[i] /= 2;
      a[i + n / 2] /= 2;
    }
    w *= wn;
  }
}
vector<int> multiply(vector<int> const& a, vector<int> const& b) {
  vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());
  int n = 1;
  while (n < a.size() + b.size()) n <<= 1;
  fa.resize(n);
  fb.resize(n);
  fft(fa, false);
  fft(fb, false);
  for (int i = 0; i < n; i++) fa[i] *= fb[i];
  fft(fa, true);
  vector<int> result(n);
  for (int i = 0; i < n; i++) result[i] = round(fa[i].real());
  return result;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
bool pali(string s) {
  long long l = s.length();
  for (int i = 0; i < l / 2; i++) {
    if (s[i] != s[l - i - 1]) return false;
  }
  return true;
}
struct p {
  long long val;
  long long id;
};
bool compare(p a, p b) {
  if (a.val == b.val) return a.id > b.val;
  return a.val > b.val;
}
long long power(long long n, long long p) {
  if (p == 0) return 1;
  long long res = power((n * n) % 1000000007, p / 2);
  if (p % 2 == 1) res = (n * res) % 1000000007;
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  long long n, k;
  cin >> n >> k;
  if (k % n != 0) {
    cout << 0 << endl;
    return 0;
  }
  n = k / n;
  vector<long long> v;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      v.push_back(i);
      if ((n / i) != i) v.push_back(n / i);
    }
  }
  sort(v.begin(), v.end());
  long long l = v.size();
  long long* dp = new long long[l]();
  dp[0] = 1;
  for (int i = 1; i < l; i++) {
    dp[i] = power(2, v[i] - 1);
    for (int j = 0; j < i; j++) {
      if (v[i] % v[j] == 0) {
        dp[i] = (dp[i] - dp[j] + 1000000007) % 1000000007;
      }
    }
  }
  cout << dp[l - 1] << endl;
}
