#include <bits/stdc++.h>
using namespace std;
const long long maxn = 35000, mod = 1e9 + 7, maxa = 2000010, maxb = 20,
                base = 737, base2 = 3079, mod2 = 1e7 + 19;
const long long inf = 2e18, infint = 110;
long long max(long long x, long long y) { return (x > y ? x : y); }
long long min(long long x, long long y) { return (x < y ? x : y); }
map<long long, long long> dp;
vector<long long> v;
vector<long long> p;
long long pw(long long x, long long y) {
  if (!y) {
    return 1;
  }
  long long res = pw(x, y / 2);
  res *= res;
  res %= mod;
  if (y & 1) {
    res *= x;
  }
  return res % mod;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, x;
  cin >> n >> x;
  if (x % n) {
    cout << 0 << endl;
    return 0;
  }
  x /= n;
  for (long long j = 2; j * j <= x; j++) {
    if (x % j) {
      continue;
    }
    p.push_back(j);
    if (j * j == x) {
      continue;
    }
    p.push_back(x / j);
  }
  if (x == 1) {
    cout << 1 << endl;
    return 0;
  }
  p.push_back(x);
  sort(p.begin(), p.end());
  dp[1] = 1;
  for (auto i : p) {
    v.clear();
    for (long long j = 2; j * j <= i; j++) {
      if (i % j) {
        continue;
      }
      v.push_back(j);
      if (j * j == i) {
        continue;
      }
      v.push_back(i / j);
    }
    v.push_back(i);
    dp[i] = pw(2, i - 1);
    for (auto u : v) {
      dp[i] -= dp[i / u] - mod;
      dp[i] %= mod;
    }
  }
  cout << dp[x] << endl;
  return 0;
}
