#include <bits/stdc++.h>
using namespace std;
const int64_t INF = 1e9, MOD = 1e9 + 7, MAXN = 1e5 + 7, MAXA = 1e6 + 5;
const long double EPS = 1e-9, PI = acos(-1);
int64_t fast_pow(int64_t num, int64_t pow) {
  if (pow == 0) return 1;
  if (pow & 1) return (fast_pow(num, pow - 1) * num) % MOD;
  int64_t half_pow = fast_pow(num, pow / 2);
  return (half_pow * half_pow) % MOD;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int64_t x, y;
  cin >> x >> y;
  if (y % x != 0) {
    cout << 0 << endl;
    return 0;
  }
  int64_t num = y / x;
  vector<int64_t> divs;
  for (int64_t i = 1; i * i <= num; ++i) {
    if (num % i == 0) {
      divs.push_back(i);
      if (i * i < num) divs.push_back(num / i);
    }
  }
  sort((divs).begin(), (divs).end());
  int64_t n = divs.size();
  vector<int64_t> answer(n);
  for (int64_t i = 0; i < n; ++i) {
    answer[i] = fast_pow(2, divs[i] - 1);
    for (int64_t j = 0; j < i; ++j)
      if (divs[i] % divs[j] == 0)
        answer[i] = (answer[i] + MOD - answer[j]) % MOD;
  }
  cout << answer.back() << endl;
  return 0;
}
