#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int maxn = 100010;
int prime[maxn], mob[maxn], isp[maxn], T;
int qpow(int b, int a = 2) {
  int res = 1;
  while (b) {
    if (b & 1) res = 1ll * res * a % mod;
    a = 1ll * a * a % mod;
    b >>= 1;
  }
  return res;
}
void Mobius() {
  mob[1] = 1;
  for (int i = 2; i < maxn; i++) {
    if (!isp[i]) prime[T++] = i, mob[i] = -1;
    for (int j = 0; j < T && i * prime[j] < maxn; j++) {
      isp[i * prime[j]] = 1;
      if (!(i % prime[j])) {
        mob[i * prime[j]] = 0;
        break;
      }
      mob[i * prime[j]] = -mob[i];
    }
  }
}
int Mob(int t) {
  if (t < maxn) return mob[t];
  for (int i = 0; prime[i] * prime[i] <= t; i++) {
    if (t % prime[i] == 0) {
      if ((t / prime[i]) % prime[i] == 0) return 0;
      return -Mob(t / prime[i]);
    }
  }
  return -1;
}
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  Mobius();
  if (M % N == 0) {
    M /= N;
    int i, ans = 0;
    for (i = 1; i * i < M; i++)
      if (M % i == 0) {
        ans = (ans + Mob(i) * qpow((M / i) - 1)) % mod;
        ans = (ans + Mob(M / i) * qpow(i - 1)) % mod;
      }
    if (i * i == M) ans = (ans + Mob(i) * qpow(i - 1)) % mod;
    printf("%d\n", (ans + mod) % mod);
  } else
    puts("0");
  return 0;
}
