#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
int x, y, val[11], tot;
inline int pw2(int b) {
  int c = 1, a = 2;
  for (; b; b >>= 1, a = 1ll * a * a % M)
    if (b & 1) c = 1ll * c * a % M;
  return c;
}
inline long long getans(int i, int p, int mu) {
  if (i > tot) return 1ll * mu * pw2(y / p - 1) % M;
  return (getans(i + 1, p, mu) + getans(i + 1, p * val[i], -mu)) % M;
}
int main(void) {
  scanf("%d%d", &x, &y);
  if (y % x)
    puts("0");
  else {
    y /= x;
    int j = y;
    for (int i = 2; 1ll * i * i <= j; i++) {
      if (j % i == 0) val[++tot] = i;
      while (j % i == 0) j /= i;
    }
    if (j > 1) val[++tot] = j;
    printf("%d\n", int(getans(1, 1, 1) + M) % M);
  }
  return 0;
}
