#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const long long INFL = 1e18 + 123;
const double PI = atan2(0, -1);
mt19937 tw(960172);
long long rnd(long long x, long long y) {
  static uniform_int_distribution<long long> d;
  return d(tw) % (y - x + 1) + x;
}
const int MOD = 1e9 + 7;
int mpow(int a, int b) {
  int ret = 1;
  while (b) {
    if (b & 1) {
      ret = (long long)ret * a % MOD;
    }
    b /= 2;
    a = (long long)a * a % MOD;
  }
  return ret;
}
map<int, int> mem;
int calc(int num) {
  if (mem.count(num)) {
    return mem[num];
  }
  if (num <= 2) {
    return 1;
  }
  int& val = mem[num];
  val = mpow(2, num - 1);
  for (int i = 1; i * i <= num; ++i) {
    if (num % i == 0) {
      val = (val - calc(i)) % MOD;
      if (i > 1 && i * i < num) {
        val = (val - calc(num / i)) % MOD;
      }
    }
  }
  if (val < 0) {
    val += MOD;
  }
  return val;
}
int main() {
  cerr << fixed << setprecision(15);
  cout << fixed << setprecision(15);
  int x, y;
  scanf("%d%d", &x, &y);
  if (y % x != 0) {
    cout << "0\n";
    return 0;
  }
  y /= x;
  cout << calc(y) << "\n";
  return 0;
}
