#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
const int M = 1e4;
const int MAX = 1e5;
int cnt, ct;
long long su[N];
long long yin[N];
long long ans, m, n;
bool vis[N];
void init() {
  cnt = 1;
  memset(vis, 1, sizeof(vis));
  vis[0] = vis[1] = 0;
  for (long long i = 2; i < N; i++) {
    if (vis[i]) {
      su[cnt++] = i;
      for (long long j = i * i; j < N; j += i) vis[j] = 0;
    }
  }
}
long long q_pow(long long x, long long y, long long mod) {
  if (!y) return 1ll;
  x %= mod;
  long long ret = 1ll;
  while (y) {
    if (y & 1) ret = ret * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ret;
}
void dfs(long long cur, long long s, long long fla) {
  if (cur >= ct) {
    ans = ((ans + fla * q_pow(2ll, n / s - 1, 1000000007)) % 1000000007 +
           1000000007) %
          1000000007;
    return;
  }
  dfs(cur + 1, s, fla);
  dfs(cur + 1, s * yin[cur], -fla);
}
int main() {
  init();
  while (scanf("%lld %lld", &m, &n) != EOF) {
    if (n % m) {
      printf("0\n");
      continue;
    }
    n /= m;
    long long mx = n;
    ct = 1, ans = 0;
    for (int i = 1; su[i] * su[i] <= mx; i++) {
      if (mx % su[i] == 0) yin[ct++] = su[i];
      while (mx % su[i] == 0) mx /= su[i];
      if (mx <= 1) break;
    }
    if (mx > 1) yin[ct++] = mx;
    dfs(1ll, 1ll, 1ll);
    printf("%lld\n", ans);
  }
  return 0;
}
