#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MOD = 1000000007;
int pw(int x, int n) {
  int ret = 1;
  while (true) {
    if (n & 1) ret = (long long)ret * x % MOD;
    if ((n >>= 1) == 0) return ret;
    x = (long long)x * x % MOD;
  }
}
int g, sum;
vector<int> getprimes(int x) {
  vector<int> ret;
  for (int i = 2; i * i <= x; ++i)
    if (x % i == 0) {
      ret.push_back(i);
      while (x % i == 0) x /= i;
    }
  if (x != 1) ret.push_back(x);
  return ret;
}
int solve() {
  if (sum % g != 0) return 0;
  sum /= g;
  g = 1;
  int ret = 0;
  vector<int> p = getprimes(sum);
  for (int i = (0); i < (1 << ((int)(p).size())); ++i) {
    int prod = 1, cnt = 0;
    for (int j = (0); j < (((int)(p).size())); ++j)
      if (i & (1 << j)) prod *= p[j], ++cnt;
    int times = sum / prod;
    int cur = pw(2, times - 1);
    if (cnt % 2 == 0)
      ret = (ret + cur) % MOD;
    else
      ret = (ret + MOD - cur) % MOD;
  }
  return ret;
}
void run() {
  scanf("%d%d", &g, &sum);
  printf("%d\n", solve());
}
int main() {
  run();
  return 0;
}
