#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e6 + 5;
const long long int mod = 1e9 + 7;
long long int dx[4] = {1, -1, 0, 0};
long long int dy[4] = {0, 0, 1, -1};
long long int pw(long long int a, long long int b) {
  long long int ret = 1;
  while (b) {
    if (b % 2 == 1) {
      ret = ret * a % mod;
    }
    b /= 2;
    a = a * a % mod;
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  long long int x, y;
  cin >> x >> y;
  if (y % x != 0) {
    cout << "0\n";
    return 0;
  }
  y = y / x;
  long long int tmp = y;
  vector<long long int> v;
  v.clear();
  for (long long int i = 2; i * i <= tmp; i++) {
    if (tmp % i == 0) {
      v.push_back(i);
      while (tmp % i == 0) {
        tmp /= i;
      }
    }
  }
  if (tmp > 1) {
    v.push_back(tmp);
  }
  long long int siz = v.size();
  long long int ans = 0;
  for (long long int mask = 0; mask < (1 << siz); mask++) {
    long long int p = 1;
    for (long long int i = 0; i < siz; i++) {
      if ((mask >> i) & 1) {
        p *= v[i];
      }
    }
    ans = (ans + (__builtin_popcount(mask) & 1 ? -1 : +1) * pw(2, y / p - 1) +
           mod) %
          mod;
  }
  cout << ans << endl;
  return 0;
}
