#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
map<long long, int> dp;
vector<long long> d;
long long bigmod(long long a, long long n, long long M) {
  long long res = 1LL;
  while (n) {
    if (n & 1) res = (res * a) % M;
    a = (a * a) % M;
    n >>= 1;
  }
  return res % M;
}
long long fun(long long num) {
  if (dp.find(num) != dp.end()) return dp[num];
  long long ret = bigmod(2, num - 1, mod);
  for (auto p : d) {
    if (p >= num) break;
    if (num % p == 0) {
      ret = (ret - fun(p) + mod) % mod;
    }
  }
  return dp[num] = ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long a, b;
  cin >> a >> b;
  if (b % a != 0) {
    cout << 0 << '\n';
    return 0;
  }
  for (long long i = 1; i * i <= b; ++i) {
    if (b % i == 0) {
      d.push_back(i);
      if (b / i != i) d.push_back(b / i);
    }
  }
  sort(d.begin(), d.end());
  long long ans = fun(b / a);
  cout << ans << '\n';
}
