#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
map<int, long long> mapp;
inline long long qpow(int k) {
  long long ans = 1, x = 2;
  while (k) {
    if (k & 1) (ans *= x) %= mod;
    (x *= x) %= mod;
    k >>= 1;
  }
  return ans;
}
inline long long dfs(int x) {
  if (x == 1) return 1;
  if (mapp[x]) return mapp[x];
  mapp[x] = qpow(x - 1);
  for (register int i = 2; i * i <= x; ++i) {
    if (!(x % i)) {
      mapp[x] = (mapp[x] - dfs(x / i) + mod) % mod;
      if (i * i != x) mapp[x] = (mapp[x] - dfs(i) + mod) % mod;
    }
  }
  return mapp[x] = (mapp[x] - 1 + mod) % mod;
}
int x, y;
signed main() {
  scanf("%d%d", &x, &y);
  if (y % x != 0) return !printf("0\n");
  printf("%lld\n", dfs(y / x));
  return 0;
}
