#include <bits/stdc++.h>
using namespace std;
const int N = 1e6, MOD = 1e9 + 7;
int f[N + 1];
int binary_power(long long a, int n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) {
      n--;
      res *= a;
      res %= MOD;
    } else {
      n >>= 1;
      a *= a;
      a %= MOD;
    }
  }
  return res;
}
int calc(int n) {
  if (n <= N && f[n] > 0) {
    return f[n];
  }
  long long res = binary_power(2ll, n - 1) - 1;
  res += MOD;
  res %= MOD;
  for (int j = 2; j * j <= n; j++) {
    if (n % j == 0) {
      int x = j, y = n / j;
      res -= calc(x);
      res += MOD;
      res %= MOD;
      if (j * j != n) {
        res -= calc(y);
        res += MOD;
        res %= MOD;
      }
    }
  }
  if (n <= N) f[n] = res;
  return res;
}
int main() {
  int x = -1, y = -1;
  scanf("%d%d", &x, &y);
  if (y % x > 0) {
    printf("0\n");
    return 0;
  }
  for (int i = 1; i <= N; i++) f[i] = -1;
  f[1] = f[2] = 1;
  int q = y / x;
  printf("%d", calc(q));
}
