#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
const long long MOD = 1e9 + 7;
const double PI = acos(-1.0);
long long Q_pow(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % MOD;
    a = (a * a) % MOD;
    b /= 2;
  }
  return res;
}
int judge(int x) {
  for (int i = 2; i * i <= x; ++i)
    if (x % i == 0) return 0;
  return 1;
}
int num[50];
int bit[25];
int main() {
  int x, y;
  cin >> x >> y;
  if (y % x != 0) return printf("0\n") * 0;
  long long k = (long long)y / x;
  if (k == 1) return 0 * printf("1\n");
  map<int, int> mp;
  mp.clear();
  int tot = 0;
  for (long long i = 2; i * i <= k; ++i) {
    if (k % i == 0) {
      if (judge(i)) {
        if (mp[i] == 0) {
          num[++tot] = i;
          mp[i] = 1;
        }
      }
      if (judge(k / i) && i != k / i) {
        if (mp[k / i] == 0) {
          num[++tot] = k / i;
          mp[k / i] = 1;
        }
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < (1 << tot); ++i) {
    int tmp = i;
    memset(bit, 0, sizeof bit);
    int p = 0, cnt = 0;
    ;
    while (tmp) {
      bit[++p] = (tmp & 1);
      tmp >>= 1;
    }
    int sys = 1;
    long long res = 1;
    for (int j = 1; j <= tot; ++j) {
      if (bit[j]) res *= num[j], sys *= -1;
    }
    ans += sys * (Q_pow(2, k / res - 1) - 1);
    if (ans < 0) ans += MOD;
    if (ans >= MOD) ans -= MOD;
  }
  cout << ans << endl;
}
