#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[2000], b[2000];
int cal(int x) { return x * (3 * x - 1) / 2; }
int getF(int x) {
  int i;
  for (i = 0; i < m; i++) {
    if (a[i] == x) {
      return b[i];
    }
  }
  return -1;
}
long long getPow(int e) {
  if (e == 0) {
    return 1;
  } else if (e == 1) {
    return 2;
  }
  long long rt = getPow(e / 2);
  rt %= 1000000007;
  rt *= rt;
  if (e % 2) {
    rt *= 2;
  }
  return rt % 1000000007;
}
long long f(int x) {
  if (x == 1) {
    return 1;
  }
  int v = getF(x);
  if (v != -1) {
    return v;
  }
  long long rt = getPow(x - 1) - 1;
  int i;
  for (i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      rt -= f(i);
      if (rt < 0) rt += 1000000007;
      rt %= 1000000007;
      if (i * i != x) {
        rt -= f(x / i);
        if (rt < 0) rt += 1000000007;
        rt %= 1000000007;
      }
    }
  }
  a[m] = x;
  b[m] = rt;
  m++;
  return rt;
}
void solve() {}
int main() {
  int x, y;
  int i;
  m = 0;
  while (scanf("%d %d", &x, &y) != EOF) {
    if (y % x) {
      printf("0\n");
    } else {
      long long rs = f(y / x);
      printf("%lld\n", rs);
    }
  }
  return 0;
}
