#include <bits/stdc++.h>
using namespace std;
long long a[10005], dp[10005], n, m, tot;
long long pow(long long mi) {
  long long res = 1;
  for (long long a = 2; mi; mi >>= 1) {
    if (mi & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
  }
  return res;
}
int main() {
  scanf("%I64d%I64d", &n, &m);
  if (m % n) return puts("0"), 0;
  for (long long i = 1; i <= sqrt(m); i++)
    if (m % i == 0) {
      if (i % n == 0) a[++tot] = i;
      if (i * i != m && m / i % n == 0) a[++tot] = m / i;
    }
  sort(a + 1, a + tot + 1);
  for (int i = tot; i; i--) {
    dp[i] = pow(m / a[i] - 1);
    for (int j = i + 1; j <= tot; j++)
      if (a[j] % a[i] == 0) dp[i] = (dp[i] - dp[j] + 1000000007) % 1000000007;
  }
  printf("%I64d\n", dp[1]);
}
