#include <bits/stdc++.h>
using namespace std;
long long int po(int a) {
  if (a == 0) return 1;
  long long int x = po(a / 2);
  x = x * x;
  x %= 1000000007;
  if (a % 2 == 0) {
    return x;
  } else {
    x = x * 2;
    x %= 1000000007;
    return x;
  }
}
int main() {
  int x, y;
  cin >> x >> y;
  if (y % x != 0) {
    cout << 0 << endl;
  } else {
    y = y / x;
    vector<int> val;
    for (int i = 1; i * i <= y; i++) {
      if (y % i == 0) {
        val.push_back(i);
        if (i * i != y) {
          val.push_back(y / i);
        }
      }
    }
    sort(val.begin(), val.end());
    vector<int> ans(val.size(), 0);
    ans[0] = 1;
    for (int i = 1; i < val.size(); i++) {
      ans[i] = po(val[i] - 1);
      for (int j = 0; j < i; j++) {
        if (val[i] % val[j] != 0) continue;
        ans[i] -= ans[j];
        ans[i] = ans[i] % 1000000007;
      }
    }
    if (ans[val.size() - 1] < 0) {
      ans[val.size() - 1] += 1000000007;
    }
    cout << ans[val.size() - 1] << endl;
  }
  return 0;
}
