#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MAXN = 2e5 + 7;
const long long MAXP = 15;
long long dp[1 << MAXP];
long long f(long long a, long long b) {
  if (b == 0) return 1;
  long long p = f(a, b / 2);
  if (b % 2 == 0) {
    return (p * p) % MOD;
  } else {
    return (((p * p) % MOD) * a) % MOD;
  }
}
long long get(long long n) { return f(2, n - 1); }
vector<long long> get_p(long long n) {
  vector<long long> res;
  long long d = 2;
  while (d * d <= n) {
    if (n % d == 0) {
      res.push_back(d);
      while (n % d == 0) {
        n /= d;
      }
    }
    ++d;
  }
  if (n != 1) res.push_back(n);
  return res;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cout.precision(40);
  long long x, y;
  cin >> x >> y;
  if (y % x) {
    cout << "0\n";
    return 0;
  } else {
    long long n = y / x;
    vector<long long> p = get_p(n);
    long long len = p.size();
    long long ans = 0;
    for (long long mask = 0; mask < (1 << len); ++mask) {
      long long counter = 0;
      long long fact = 1;
      for (long long i = 0; i < len; ++i) {
        if ((mask >> i) & 1) {
          counter++;
          fact *= p[i];
        }
      }
      long long val = get(n / fact);
      if (counter % 2 == 0) {
        ans += val;
      } else {
        ans -= val;
      }
      ans %= MOD;
    }
    cout << (ans + MOD) % MOD;
  }
  return 0;
}
