#include <bits/stdc++.h>
#pragma GCC optimize("-O2")
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
const int LIM = 1e5 + 5, MOD = 1e9 + 7;
int t, n, m, k, x, y;
int is_com[LIM];
vector<int> pr;
void sieve() {
  for (int i = 2; i < LIM; i++) {
    if (!is_com[i]) pr.push_back(i);
    for (auto &it : pr) {
      if (it * i >= n) break;
      is_com[i * it] = 1;
      if (i % it == 0) {
        break;
      }
    }
  }
}
long long int powm(long long int x, long long int pw, long long int MOD) {
  long long int res = 1;
  while (pw) {
    if (pw & 1LL) res = ((res * x)) % MOD;
    pw >>= 1;
    x = ((x * x)) % MOD;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  sieve();
  long long int x, y;
  cin >> x >> y;
  long long int ans = 0;
  if (y % x == 0) {
    map<int, int> fac;
    y /= x;
    long long int cp = y;
    for (auto &it : pr) {
      if (cp == 1) break;
      while (cp % it == 0) fac[it]++, cp /= it;
    }
    if (cp > 1) fac[cp]++;
    for (long long int i = 1; i < (long long int)1e5; ++i) {
      if (i * i > y) break;
      if (y % i == 0) {
        map<int, int> f;
        cp = i;
        for (auto &it : fac) {
          if (cp == 1) break;
          while (cp % it.first == 0) f[it.first]++, cp /= it.first;
        }
        int mu = 1;
        for (auto &it : f) {
          if (it.second > 1)
            mu = 0;
          else
            mu *= -1;
        }
        ans += mu * powm(2, y / i - 1, MOD);
        if (y / i != i) {
          map<int, int> f;
          cp = y / i;
          for (auto &it : fac) {
            if (cp == 1) break;
            while (cp % it.first == 0) f[it.first]++, cp /= it.first;
          }
          int mu = 1;
          for (auto &it : f) {
            if (it.second > 1)
              mu = 0;
            else
              mu *= -1;
          }
          ans += mu * powm(2, i - 1, MOD);
        }
        ans %= MOD;
      }
    }
    cout << (ans + MOD) % MOD << "\n";
  } else
    cout << 0 << "\n";
  return 0;
}
