#include <bits/stdc++.h>
using namespace std;
const long long MD = 1e9 + 7;
map<long long, long long> dp;
long long pw(long long a, long long b) {
  long long rs = 1;
  while (b > 0) {
    if (b & 1) {
      rs = (rs * a) % MD;
    }
    a = (a * a) % MD;
    b /= 2;
  }
  return rs;
}
long long solve(long long a) {
  if (a == 1) {
    return 1;
  }
  if (dp.find(a) != dp.end()) return dp[a];
  dp[a] = pw(2, a - 1);
  for (long long i = 1; i * i <= a; ++i) {
    if (a % i == 0) {
      if (i != 1) {
        dp[a] -= solve(a / i);
        dp[a] %= MD;
        dp[a] += MD;
        dp[a] %= MD;
      }
      long long nx = a / i;
      if (nx != -1 && nx != i) {
        dp[a] -= solve(a / nx);
        dp[a] %= MD;
        dp[a] += MD;
        dp[a] %= MD;
      }
    }
  }
  return dp[a];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long x, y;
  cin >> x >> y;
  if (y % x != 0) {
    cout << 0 << "\n";
    return 0;
  }
  cout << solve(y / x) << "\n";
  return 0;
}
