#include <bits/stdc++.h>
using namespace std;
int n, m, as = 0;
template <class T>
void read(T &x) {
  char ch;
  bool ok;
  for (ok = 0, ch = getchar(); !isdigit(ch); ch = getchar())
    if (ch == '-') ok = 1;
  for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar())
    ;
  if (ok) x = -x;
}
int fp(int x, int y) {
  int asi = 1;
  while (y) {
    if (y & 1) asi = 1ll * asi * x % 1000000007;
    x = 1ll * x * x % 1000000007;
    y >>= 1;
  }
  return asi;
}
int get_miu(int x) {
  int asi = 1;
  for (int i = (2), en = (x); i <= en; ++i) {
    if (i * i > x) break;
    if (x % i == 0) {
      asi = 1000000007 - asi;
      x /= i;
      if (x % i == 0) return 0;
    }
  }
  if (x != 1) asi = 1000000007 - asi;
  return asi;
}
int main() {
  read(n);
  read(m);
  if (m % n) {
    puts("0");
    return 0;
  };
  m /= n;
  for (int i = (1), en = (m); i <= en; ++i) {
    if (i * i > m) break;
    if (m % i == 0) {
      as = (as + 1ll * fp(2, m / i - 1) * get_miu(i) % 1000000007) % 1000000007;
      if (i * i != m)
        as = (as + 1ll * fp(2, i - 1) * get_miu(m / i) % 1000000007) %
             1000000007;
    }
  }
  printf("%d\n", as);
  return 0;
}
