#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long x, y;
long long kuai(long long x, int y) {
  long long ans = 1;
  x %= mod;
  while (y) {
    if (y & 1) (ans *= x) %= mod;
    (x *= x) %= mod;
    y >>= 1;
  }
  return ans;
}
map<int, long long> mapp;
long long work(int n) {
  if (mapp[n]) return mapp[n];
  mapp[n] = kuai(2, n - 1) % mod;
  for (int i = 1; i * i <= n; i++)
    if (n % i == 0) {
      mapp[n] = ((mapp[n] - work(i)) % mod + mod) % mod;
      if (i != (n / i) && i != 1)
        mapp[n] = ((mapp[n] - work(n / i)) % mod + mod) % mod;
    }
  return mapp[n];
}
int main() {
  cin >> x >> y;
  mapp[1] = 1;
  if (y % x != 0)
    cout << 0 << endl;
  else
    cout << work(y / x) % mod << endl;
  return 0;
}
