#include <bits/stdc++.h>
using namespace std;
const int MAXN = -1, MOD = 1e9 + 7;
long long expmod(long long b, long long e) {
  if (!e) return 1;
  return (((e % 2) ? b : 1) * expmod(b * b % MOD, e / 2)) % MOD;
}
int n, g;
vector<int> D;
map<int, long long> Sol;
long long solve(int p) {
  vector<int> A;
  for (int i = (0); i < (int)(D.size()); i++)
    if (!(p % D[i])) A.push_back(D[i]);
  A.pop_back();
  long long ans = expmod(2, p - 1);
  for (int i = (0); i < (int)(A.size()); i++) ans = (ans - Sol[A[i]]) % MOD;
  return (ans + MOD) % MOD;
}
int main() {
  while (cin >> g >> n) {
    if (n % g) {
      cout << 0 << endl;
      continue;
    }
    D.clear();
    n /= g;
    for (int i = 1; i * i <= n; i++)
      if (!(n % i)) {
        D.push_back(i);
        D.push_back(n / i);
      }
    int x = D.back();
    if (x * x == n) D.pop_back();
    sort(D.begin(), D.end());
    for (int i = (0); i < (int)(D.size()); i++) Sol[D[i]] = solve(D[i]);
    printf("%lld\n", Sol[n]);
  }
  return 0;
}
