#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool uin(T& a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
inline bool uax(T& a, T b) {
  return a < b ? (a = b, true) : false;
}
const long long MOD = 1e9 + 7;
map<int, long long> f;
long long mypow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = a * res % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return res;
}
long long gogo(int n) {
  if (f.find(n) != f.end()) return f[n];
  long long sub = 1;
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      sub = (sub + gogo(i)) % MOD;
      if (i != n / i) sub = (sub + gogo(n / i)) % MOD;
    }
  }
  f[n] = (mypow(2, n - 1) - sub + MOD) % MOD;
  return f[n];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long x, y;
  cin >> x >> y;
  if (y % x) {
    cout << 0 << '\n';
    return 0;
  }
  f[1] = 1;
  cout << gogo(y / x) << '\n';
}
