#include <bits/stdc++.h>
using namespace std;
int d[110], tot;
int n;
int fpow(int a, int b) {
  int ans = 1, t = a;
  while (b) {
    if (b & 1) ans = (long long)ans * t % 1000000007;
    t = (long long)t * t % 1000000007;
    b >>= 1;
  }
  return ans;
}
int ans = 0;
void dfs(int x, int mul, int t) {
  if (x > tot) {
    ans = ((ans + t * fpow(2, n / mul - 1)) % 1000000007 + 1000000007) %
          1000000007;
    return;
  }
  dfs(x + 1, mul, t);
  dfs(x + 1, mul * d[x], -t);
  return;
}
int main() {
  int x, y;
  cin >> x >> y;
  if (y % x != 0) {
    puts("0");
    return 0;
  }
  int t = n = y / x;
  for (int i = 2; i <= t; i++)
    if (t % i == 0) {
      d[++tot] = i;
      while (t % i == 0) t /= i;
    }
  dfs(1, 1, 1);
  cout << ans << "\n";
  return 0;
}
