#include <bits/stdc++.h>
using namespace std;
int x, y, pri[500005], now, D, c[500005], d[500005], vis[500005], Ans[500005];
long long ans;
map<int, int> mp;
void get(int n) {
  for (int i = 2; i <= n; i++) {
    if (!vis[i]) pri[++pri[0]] = i;
    for (int j = i; j <= n; j += i) vis[j] = 1;
  }
}
long long Get(int x) {
  if (x == 0) return 1;
  if (x == 1) return 2;
  long long tmp = Get(x / 2);
  tmp = tmp * tmp % 1000000007;
  if (x & 1) tmp = tmp * 2 % 1000000007;
  return tmp;
}
int f(int x) { return (Get(x - 1) - 1 + 1000000007) % 1000000007; }
int main() {
  get(100000);
  scanf("%d%d", &x, &y);
  now = y / x;
  D = now;
  if (y % x != 0) {
    printf("0\n");
    return 0;
  }
  for (int i = 1; i * i <= D; i++) {
    if ((now % i) == 0) {
      c[++c[0]] = i;
      if (i * i != now) c[++c[0]] = now / i;
    }
  }
  sort(c + 1, c + 1 + c[0]);
  ans = f(D);
  for (int i = c[0]; i >= 1; i--) {
    Ans[i] = Get(D / c[i] - 1);
    for (int j = i + 1; j <= c[0]; j++)
      if (c[j] % c[i] == 0)
        Ans[i] = (Ans[i] - Ans[j] + 1000000007) % 1000000007;
  }
  printf("%d\n", Ans[1]);
}
