#include <bits/stdc++.h>
using namespace std;
long long int i, j, n;
long long int x, y;
map<pair<long long int, long long int>, long long int> dp;
inline long long int modpow(long long int a, long long int b) {
  long long int ans = 1, c = 1000000007;
  a = a % c;
  while (b) {
    if (b & 1) ans = (ans * a) % 1000000007;
    a = (a * a) % 1000000007;
    b = b / 2;
  }
  return ans;
}
long long int solve(long long int sum, long long int gcd) {
  if (dp.find({sum, gcd}) != dp.end()) return dp[{sum, gcd}];
  if (sum == 1 && gcd == 1) return 1;
  if (sum == 1 && gcd != 1) return 0;
  long long int ans = modpow(2, sum - 1);
  for (long long int i = 1; i * i <= sum; i++) {
    if (sum % i == 0) {
      long long int factor1 = i;
      long long int factor2 = sum / i;
      if (factor1 != 1)
        ans = (ans - solve(sum / factor1, 1) + 1000000007) % 1000000007;
      ;
      if (i * i != sum) {
        ans = (ans - solve(sum / factor2, 1) + 1000000007) % 1000000007;
        ;
      }
    }
  }
  return dp[{sum, 1}] = ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> x >> y;
  if (y % x != 0) {
    cout << 0;
  } else {
    y /= x;
    long long int newsum = y;
    cout << solve(newsum, 1);
  }
  return 0;
}
