#include <bits/stdc++.h>
using namespace std;
template <typename T>
T sqr(const T &first) {
  return first * first;
}
template <typename T>
T my_abs(const T &first) {
  return first < 0 ? -first : first;
}
const int INF = (int)1e9;
const long long LINF = (long long)4e18;
const long long INF64 = LINF;
const long long INFLL = LINF;
const long double EPS = 1e-9;
const long double PI = 3.1415926535897932384626433832795;
const int N = 1000 * 100 + 9;
const int MOD = int(1e9) + 7;
int g, sum;
bool read() {
  if (!(cin >> g >> sum)) return false;
}
int bp(int a, int n) {
  int res = 1;
  for (; n > 0; n >>= 1) {
    if (n & 1) res = (res * 1LL * a) % MOD;
    a = (a * 1LL * a) % MOD;
  }
  return res;
}
void solve() {
  if (sum % g) {
    puts("0");
    return;
  }
  sum /= g;
  vector<int> v;
  int nsum = sum;
  for (int i = 2; i * i <= nsum; ++i) {
    if (nsum % i == 0) {
      v.push_back(i);
      while (nsum % i == 0) nsum /= i;
    }
  }
  if (nsum > 1) v.push_back(nsum);
  long long res = 0;
  for (int msk = 0; msk < int(1 << int(v.size())); ++msk) {
    int d = 1;
    bool na = true;
    for (int i = 0; i < int(int(v.size())); ++i)
      if ((1 << i) & msk) d *= v[i], na ^= true;
    res += (na ? bp(2, sum / d - 1) : -bp(2, sum / d - 1));
  }
  res = ((res % MOD) + MOD) % MOD;
  cout << res << endl;
}
int main() {
  srand((unsigned int)time(NULL));
  cout << setprecision(15) << fixed;
  read();
  solve();
  return 0;
}
