#include <bits/stdc++.h>
using namespace std;
long long gcd(long long n1, long long n2) {
  if (!n1) return n2;
  if (!n2) return n1;
  if (n1 % n2 == 0) return n2;
  return gcd(n2, n1 % n2);
}
long long powmod(long long base, long long exponent) {
  base %= 1000000007;
  long long ans = 1;
  while (exponent) {
    if (exponent & 1) ans = (ans * base) % 1000000007;
    base = (base * base) % 1000000007;
    exponent /= 2;
  }
  ans %= 1000000007;
  return ans;
}
int dp[1000100 + 1];
vector<int> factors;
int main() {
  int x, y, i, j;
  scanf("%d", &x);
  scanf("%d", &y);
  if (y % x) {
    printf("%d\n", 0);
    return 0;
  }
  for (i = 1; i * i < y; i++)
    if (y % i == 0) {
      factors.push_back(i);
      factors.push_back(y / i);
    }
  if (i * i == y) factors.push_back(i);
  sort(factors.begin(), factors.end());
  for (i = 0; i < factors.size(); i++) {
    dp[i] = powmod(2, (y / factors[i]) - 1);
  }
  for (i = factors.size() - 1; i >= 0; i--) {
    for (j = i + 1; j < factors.size(); j++)
      if (factors[j] % factors[i] == 0) {
        dp[i] -= dp[j];
        if (dp[i] < 0) dp[i] += 1000000007;
      }
  }
  for (i = 0; i < factors.size(); i++) {
    if (factors[i] == x) {
      printf("%d\n", dp[i]);
      break;
    }
  }
  return 0;
}
