#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
map<int, int> mapping;
map<int, int>::iterator it;
int pow2(int e) {
  long long base = 2;
  long long res = 1;
  while (e) {
    if (e & 1) res = (res * base) % MOD;
    base = (base * base) % MOD;
    e >>= 1;
  }
  return (int)res;
}
int solve(const int sum) {
  if (sum == 1) return 1;
  it = mapping.find(sum);
  if (it != mapping.end()) return it->second;
  int tot = pow2(sum - 1) - 1;
  int until = sqrt(sum);
  int j;
  for (int i = 2; i <= until; i++) {
    if (sum % i == 0) {
      j = sum / i;
      tot = ((tot + MOD) - solve(sum / i)) % MOD;
      if (i != j) tot = ((tot + MOD) - solve(sum / j)) % MOD;
    }
  }
  return mapping[sum] = tot;
}
int main() {
  int x, y;
  scanf("%d %d", &x, &y);
  if (y % x)
    puts("0");
  else
    printf("%d\n", solve(y / x));
  return 0;
}
