#include <bits/stdc++.h>
using namespace std;
map<long long, long long> mp;
const long long m = 1e9 + 7;
long long fexp(long long base, long long exp) {
  if (exp == 0) return 1;
  if (exp == 1) return base;
  long long res = fexp(base, exp / 2);
  res = (res * res) % m;
  if (exp % 2 != 0) res = (res * base) % m;
  return res;
}
long long solve(long long x) {
  if (x == 1) return 1;
  if (mp.find(x) != mp.end()) return mp[x];
  long long ans = fexp(2LL, x - 1);
  for (int i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      ans = (ans - solve(i) + m) % m;
      if (i * i != x && i != 1) ans = (ans - solve(x / i) + m) % m;
    }
  }
  mp[x] = ans;
  return mp[x];
}
int main() {
  long long x, y;
  cin >> x >> y;
  if (y % x != 0) {
    cout << "0";
    return 0;
  }
  long long ans = solve(y / x);
  cout << (ans) % m;
  return 0;
}
