#include <bits/stdc++.h>
using namespace std;
const long long mo = 1e9 + 7;
long long x, y;
map<long long, long long> mp;
long long qpow(long long a, long long b) {
  long long s = 1;
  while (b) {
    if (b & 1) s = s * a % mo;
    a = a * a % mo;
    b >>= 1;
  }
  return s;
}
long long solve(long long n) {
  if (n == 1) return 1;
  if (mp.count(n)) return mp[n];
  long long ans = qpow(2, n - 1);
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ans = (ans - solve(i) + mo) % mo;
      if (i * i != n) ans = (ans - solve(n / i) + mo) % mo;
    }
  }
  return mp[n] = (ans - 1 + mo) % mo;
}
int main() {
  scanf("%lld%lld", &x, &y);
  if (y % x) {
    printf("0");
    return 0;
  }
  printf("%lld", solve(y / x));
  return 0;
}
