#include <bits/stdc++.h>
using namespace std;
map<long long, long long> dp;
long long fastPow(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret = (ret * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return ret;
}
long long cc(long long y) {
  if (dp.find(y) != dp.end()) return dp[y];
  dp[y] = fastPow(2, y - 1);
  for (int i = 2; i * i <= y; i++) {
    if (!(y % i)) {
      dp[y] = (dp[y] - cc(i) + 1000000007) % 1000000007;
      if (i != y / i) {
        dp[y] = (dp[y] - cc(y / i) + 1000000007) % 1000000007;
      }
    }
  }
  dp[y]--;
  return dp[y];
}
int main() {
  long long x, y;
  cin >> x >> y;
  if (!(y % x)) {
    y /= x;
    if (y == 1) {
      cout << 1 << endl;
      return 0;
    }
    cout << cc(y) << endl;
    return 0;
  }
  cout << 0 << endl;
  return 0;
}
