#include <bits/stdc++.h>
using namespace std;
long long mod = (long long)1e9 + 7;
long long po(long long a, long long k) {
  long long res = 1;
  while (k) {
    if (k & 1) res = res * a % mod;
    a = a * a % mod;
    k >>= 1;
  }
  return res;
}
int main() {
  long long x, y;
  cin >> x >> y;
  if (y % x != 0) {
    cout << 0 << endl;
    return 0;
  }
  y = y / x;
  if (y == 1) {
    cout << 1 << endl;
    return 0;
  }
  long long i;
  vector<long long> f;
  for (i = 1; i * i <= y; i++) {
    if (y % i == 0) {
      f.push_back(i);
      if (y != i * i) {
        f.push_back(y / i);
      }
    }
  }
  long long j;
  sort(f.begin(), f.end());
  long long res[f.size()];
  for (i = f.size() - 1; i >= 0; i--) {
    res[i] = po(2, y / f[i] - 1);
    for (j = i + 1; j < f.size(); j++) {
      if (f[j] % f[i] == 0) res[i] = (res[i] - res[j] + mod) % mod;
    }
  }
  cout << res[0] << endl;
}
