#include <bits/stdc++.h>
using namespace std;
long long inf = (long long)2e18;
const int mod = 1000000007;
int n, m;
long long pow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long q, t, k, u, v;
  long long x, a, b, c, d, y, l, p;
  cin >> n >> k;
  if (k % n != 0) {
    cout << 0 << '\n';
    return 0;
  }
  n = k / n;
  vector<int> prime;
  m = n;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      while (n % i == 0) n /= i;
      prime.push_back(i);
    }
  }
  if (n != 1) prime.push_back(n);
  n = m;
  c = 0;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (i * i == n) {
        a = i;
        t = 0;
        u = -2;
        for (int j : prime) {
          if (a % j == 0) {
            t++;
            a /= j;
            if (a % j == 0) {
              u = 0;
              break;
            }
          }
        }
        u = u != 0 ? t & 1 ? -1 : 1 : 0;
        (c += pow(2, n / i - 1, mod) * u) %= mod;
      } else {
        a = i;
        t = 0;
        u = -2;
        for (int j : prime) {
          if (a % j == 0) {
            t++;
            a /= j;
            if (a % j == 0) {
              u = 0;
              break;
            }
          }
        }
        u = u != 0 ? t & 1 ? -1 : 1 : 0;
        (c += pow(2, n / i - 1, mod) * u) %= mod;
        ;
        a = n / i;
        t = 0;
        u = -2;
        for (int j : prime) {
          if (a % j == 0) {
            t++;
            a /= j;
            if (a % j == 0) {
              u = 0;
              break;
            }
          }
        }
        u = u != 0 ? t & 1 ? -1 : 1 : 0;
        (c += pow(2, i - 1, mod) * u) %= mod;
      }
    }
  }
  cout << (c + mod) % mod << '\n';
  return 0;
}
