#include <bits/stdc++.h>
using namespace std;
long long int k = 0;
map<long long int, long long int> dp;
long long int MOD = 1e9 + 7;
long long int exp(long long int n, long long int e) {
  if (e == 0) return 1;
  if (e == 1) return n;
  if (e % 2 == 0)
    return (exp((n * n) % MOD, e / 2));
  else
    return (n * (exp((n * n) % MOD, e / 2))) % MOD;
}
void func(long long int n) {
  if (dp.find(n) != dp.end()) return;
  long long int ans = 0;
  map<long long int, long long int> temp;
  for (int i = 2; i <= ((sqrt(n)) + 3); i++) {
    if (n % i == 0 && i != n) {
      func(i);
      func(n / i);
      if (i != (n / i) && temp[i] != 1) {
        temp[i] = 1;
        temp[n / i] = 1;
        ans = (ans + dp[n / i] + dp[i]) % MOD;
      } else if (temp[i] != 1) {
        temp[i] = 1;
        ans = (ans + dp[i]) % MOD;
      }
    }
  }
  ans = ans + 1;
  ans = ((exp(2, n - 1)) - ans + MOD) % MOD;
  dp[n] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int x, y;
  cin >> x >> y;
  if (y % x != 0)
    cout << 0 << endl;
  else {
    k = y / x;
    dp[1] = 1;
    func(k);
    cout << dp[k] << endl;
  }
  return 0;
}
