#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
int Pow(int b, int p) {
  if (!p) return 1;
  long long z = Pow(b, p / 2);
  if (p & 1) return z * z % M * b % M;
  return z * z % M;
}
vector<int> ls;
int mobius(int x) {
  if (x == 1) return 1;
  int ret = 1;
  for (auto &w : ls) {
    if (x % w) continue;
    if (x % ((long long)w * w) == 0) return 0;
    ret = -ret;
  }
  return ret;
}
int main() {
  int x, y;
  cin >> x >> y;
  if (y % x) {
    puts("0");
    return 0;
  }
  y /= x;
  int n = y;
  for (int i = 2; i * i <= n; ++i)
    if (n % i == 0) {
      while (n % i == 0) n /= i;
      ls.push_back(i);
    }
  if (n != 1) ls.push_back(n);
  n = y;
  int res = 0;
  for (int i = 1; i * i <= n; ++i)
    if (n % i == 0) {
      int w = n / i;
      res += mobius(w) * Pow(2, i - 1);
      res %= M;
      if (n / i != i) {
        int w = n / (n / i);
        res += mobius(w) * Pow(2, n / i - 1);
        res %= M;
      }
    }
  if (res < 0) res += M;
  printf("%d\n", res);
  return 0;
}
