#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
void yes() {
  cout << "Yes"
       << "\n";
}
void no() {
  cout << "No"
       << "\n";
}
struct Sync_stdio {
  Sync_stdio() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
  }
} _sync_stdio;
struct FAIL {
  FAIL() {
    cout << "CHANGE!!!"
         << "\n";
  }
};
long long pow_fast(long long x, long long y) {
  if (y == 0) {
    return 1;
  }
  if (y % 2) {
    return x * pow_fast(x, y - 1) % MOD;
  }
  long long t = pow_fast(x, y / 2);
  return t * t % MOD;
}
vector<int> divisors;
vector<int> prime_divisors;
long long g(int x) { return pow_fast(2, x - 1); }
long long mebius(int x) {
  int res = 0;
  for (int prime : prime_divisors) {
    if (x % prime == 0) {
      x /= prime;
      res ^= 1;
      if (x % prime == 0) {
        return 0;
      }
    }
  }
  if (!res) {
    return 1;
  }
  return -1;
}
long long f(int x) {
  long long res = 0;
  for (int div : divisors) {
    res += (mebius(div) * g(x / div)) % MOD;
    res += MOD;
    res %= MOD;
  }
  return res;
}
vector<int> get_divisors(int n) {
  int s = sqrt(n);
  vector<int> div;
  for (int i = (1); i < (s + 1); ++i) {
    if (n % i == 0) {
      div.push_back(i);
    }
  }
  vector<int> div2;
  for (auto i : div) {
    div2.push_back(n / i);
  }
  if (div2.back() == div.back()) {
    div2.pop_back();
  }
  reverse(div2.begin(), div2.end());
  div.insert(div.end(), div2.begin(), div2.end());
  return div;
}
vector<int> get_prime_divisors(int n) {
  int s = sqrt(n);
  vector<int> res;
  for (int i = (2); i < (s + 1); ++i) {
    if (n % i == 0) {
      res.push_back(i);
      while (n % i == 0) {
        n /= i;
      }
    }
  }
  if (n > 1) {
    res.push_back(n);
  }
  return res;
}
int main() {
  int k, n;
  cin >> k >> n;
  if (n % k) {
    cout << 0;
    return 0;
  }
  n /= k;
  divisors = get_divisors(n);
  prime_divisors = get_prime_divisors(n);
  cout << f(n);
}
