#include <bits/stdc++.h>
using namespace std;
const int iinf = 0x3f3f3f3f;
const long long linf = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
int Pow(int a, int first) {
  int res = 1;
  for (; first; a = 1ll * a * a % mod, first >>= 1)
    if (first & 1) res = 1ll * res * a % mod;
  return res;
}
int ga, sa, sq;
vector<int> d;
int dfs(int i, int s) {
  if (i == int((d).size())) return Pow(2, s - 1);
  return (dfs(i + 1, s) - dfs(i + 1, s / d[i])) % mod;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> ga >> sa;
  if (sa % ga) return cout << 0 << '\n', 0;
  sa /= ga;
  int l = -1, r = sa + 100;
  while (r - l > 1) {
    int mid = (r + l) >> 1;
    if (1ll * mid * mid <= 1ll * sa)
      l = mid;
    else
      r = mid;
  }
  sq = l;
  int tmp = sa;
  for (int i = (2), I = (sq + 1); i < I; i++)
    if (tmp % i == 0) {
      d.push_back(i);
      while (tmp % i == 0) tmp /= i;
    }
  if (tmp > 1) d.push_back(tmp), tmp = 1;
  cout << (dfs(0, sa) + mod) % mod << '\n';
  return 0;
}
