#include <bits/stdc++.h>
using namespace std;
const unsigned long long int modp = 1000000007;
int maxp;
unsigned long long int pow2(int p) {
  unsigned long long int ans;
  if (p == 0) return 1;
  if (p == 1) return 2;
  ans = (pow2(p / 2));
  ans = (ans * ans) % modp;
  if (p % 2) ans = (ans * 2) % modp;
  return ans;
}
unsigned long long int seqCount(int t, map<int, unsigned long long int>& res) {
  map<int, unsigned long long int>::iterator it;
  it = res.find(t);
  if (it != res.end()) return it->second;
  unsigned long long int ans = (pow2(t - 1) - 1) % modp;
  int ti = 2;
  while (ti <= floor(sqrt(t)) && ti <= t / 2) {
    if (t % ti == 0) {
      ans = (ans - seqCount(t / ti, res) + modp) % modp;
      if (t / ti != ti) ans = (ans - seqCount(ti, res) + modp) % modp;
    }
    ti++;
  }
  res.insert(pair<int, unsigned long long int>(t, ans % modp));
  return ans % modp;
}
int main() {
  int x, y;
  cin >> x >> y;
  if (y % x) {
    cout << "0";
    return 0;
  }
  map<int, unsigned long long int> res;
  res.insert(pair<int, unsigned long long int>(1, 1));
  cout << seqCount(y / x, res);
  return 0;
}
