#include <bits/stdc++.h>
using namespace std;
long long x, y;
const long long pri = 1e9 + 7;
long long ans = 0;
vector<long long> prim;
bool notPri[100005];
long long myPow(long long a, long long b) {
  long long ret = 1;
  while (b != 0) {
    if (b % 2 == 1) {
      ret = (ret * a) % pri;
    }
    a = (a * a) % pri;
    b /= 2;
  }
  return ret;
}
void pro() {
  vector<long long> st;
  long long temp = y;
  for (long long j = 0; j < prim.size(); j++) {
    if (temp == 1) break;
    bool in = false;
    while (temp % prim[j] == 0) {
      in = true;
      temp /= prim[j];
    }
    if (in) st.push_back(prim[j]);
  }
  if (temp != 1) st.push_back(temp);
  long long mask = (1 << st.size()) - 1;
  for (long long i = 1; i <= mask; i++) {
    temp = 1;
    for (long long j = 0; j <= st.size() - 1; j++) {
      if ((i & (1 << j)) != 0) temp *= st[j];
    }
    if (__builtin_popcount(i) % 2 == 1)
      ans = (ans - myPow(2, (y / temp) - 1) + pri) % pri;
    else
      ans = (ans + myPow(2, (y / temp) - 1)) % pri;
  }
}
void pre() {
  notPri[0] = true;
  notPri[1] = true;
  for (long long i = 2; i <= 100005 - 1; i++) {
    if (notPri[i])
      continue;
    else
      prim.push_back(i);
    for (int j = 2 * i; j < 100005; j += i) {
      notPri[j] = true;
    }
  }
}
int main() {
  pre();
  ios_base::sync_with_stdio(false);
  long long precision = numeric_limits<long double>::digits10;
  cin >> x >> y;
  if (y % x == 0) {
    y /= x;
    ans += myPow(2, y - 1);
    pro();
  }
  cout << ans << "\n";
}
