#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int MAX = 1e5 + 5;
const long long MOD = 1000000007;
const long long MOD2 = 2010405347;
const long long INF = 2e18;
const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 555;
long long n, x, y, ans;
vector<int> fc;
inline long long f(int y) {
  --y;
  long long x = 2, ret = 1;
  while (y) {
    if (y & 1) ret = ret * x % MOD;
    x = x * x % MOD;
    y >>= 1;
  }
  return ret;
}
void bf(int pos, int nw, bool st) {
  if (pos == fc.size()) {
    if (st)
      ans += f(n / nw);
    else
      ans -= f(n / nw);
    return;
  }
  bf(pos + 1, nw, st);
  bf(pos + 1, nw * fc[pos], st ^ 1);
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> x >> y;
  if (y % x != 0) return cout << "0\n", 0;
  n = y / x;
  for (int i = 2; i * i <= n; ++i)
    if (n % i == 0) {
      fc.push_back(i);
      while (n % i == 0) n /= i;
    }
  if (n != 1) fc.push_back(n);
  n = y / x;
  bf(0, 1, 1);
  ans %= MOD;
  if (ans < 0) ans += MOD;
  cout << ans << '\n';
  return 0;
}
