#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
vector<int> dv[N];
map<int, int> M;
int fe(int x, int k) {
  int res = 1;
  while (k) {
    if (k & 1) res = (long long)res * x % mod;
    x = (long long)x * x % mod;
    k >>= 1;
  }
  return res;
}
int dist(int n) { return fe(2, n - 1); }
int f(int n) {
  if (M.count(n)) return M[n];
  int res = dist(n);
  vector<int> d;
  if (n < N)
    d = dv[n];
  else {
    for (int i = 1; i * i <= n; i++) {
      if (n % i == 0) {
        if (i != 1) d.push_back(i);
        if (i * i != n) d.push_back(n / i);
      }
    }
  }
  for (auto x : d) res = (res + mod - f(n / x)) % mod;
  return M[n] = res;
}
int main() {
  for (int i = 2; i < N; i++)
    for (int j = i; j < N; j += i) dv[j].push_back(i);
  int n, m;
  scanf("%d %d", &n, &m);
  printf("%d\n", m % n ? 0 : f(m / n));
  return 0;
}
