#include <bits/stdc++.h>
using namespace std;
long long int Power(long long int a, long long int b) {
  long long int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % 1000000007ll;
    }
    a = (a * a) % 1000000007ll;
    b /= 2;
  }
  return res;
}
map<long long int, long long int> dp;
long long int go(long long int z) {
  if (z == 1) {
    return 1;
  }
  if (dp.find(z) != dp.end()) {
    return dp[z];
  }
  long long int res = Power(2, z - 1ll);
  for (long long int i = 2; i * i <= z; i++) {
    if (z % i == 0) {
      res = (res - go(i) + 1000000007ll) % 1000000007ll;
      if (i * i != z) {
        res = (res - go(z / i) + 1000000007ll) % 1000000007ll;
      }
    }
  }
  res = (res - go(1) + 1000000007ll) % 1000000007ll;
  return dp[z] = res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int x, y;
  cin >> x >> y;
  if (y % x) {
    cout << "0"
         << "\n";
    return 0;
  }
  long long int z = y / x;
  cout << go(z) << "\n";
}
