#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 1e6 + 8;
int N, M, K, Q;
int x, y;
int fast_pow(int a, int b) {
  int ret = 1;
  while (b != 0) {
    if (b & 1) {
      ret = 1LL * ret * a % MOD;
    }
    a = 1LL * a * a % MOD;
    b >>= 1;
  }
  return ret;
}
void preprocess() {}
int solution() {
  if (y % x) return 0;
  int t = y / x;
  int gt = fast_pow(2, t - 1);
  vector<int> divs;
  for (int i = 1; i * i <= t; i++) {
    if (t % i == 0) {
      divs.emplace_back(i);
      if (t / i != i) divs.emplace_back(t / i);
    }
  }
  sort(divs.begin(), divs.end());
  vector<int> dp(divs.size(), 0);
  dp[0] = 1;
  for (int i = 1; i < divs.size(); i++) {
    int cur = 0;
    for (int j = 0; j < i; j++) {
      if (divs[i] % divs[j] == 0) {
        cur = (0LL + cur + dp[j]) % MOD;
      }
    }
    dp[i] = (fast_pow(2, divs[i] - 1) - cur + MOD) % MOD;
  }
  return dp.back();
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  while (cin >> x >> y) {
    cout << solution() << '\n';
  }
  return 0;
}
