#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
map<int, int> mp;
int qpow(int x, int y) {
  int ans = 1;
  while (y) {
    if (y & 1) {
      ans = (long long)ans * x % mod;
    }
    y >>= 1;
    x = (long long)x * x % mod;
  }
  return ans;
}
int solve(int x) {
  if (x == 1) {
    return 1;
  }
  if (mp[x]) {
    return mp[x];
  }
  mp[x] = qpow(2, x - 1);
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      mp[x] = (mp[x] - solve(x / i) + mod) % mod;
      if (i * i != x) {
        mp[x] = (mp[x] - solve(i) + mod) % mod;
      }
    }
  }
  (mp[x] += mod - 1) %= mod;
  return mp[x];
}
int main() {
  int x, y;
  cin >> x >> y;
  if (y % x) {
    puts("0");
    return 0;
  }
  cout << solve(y / x) << endl;
  return 0;
}
