#include <bits/stdc++.h>
using namespace std;
vector<int> tt;
map<int, int> mp;
int mul(int a, int b) {
  int ret = 1;
  while (b > 0) {
    if (b % 2) {
      ret = (int)(1LL * ret * a % 1000000007);
    }
    a = (int)(1LL * a * a % 1000000007);
    b /= 2;
  }
  return ret;
}
void prime(int a) {
  int lm = sqrt(a);
  for (int i = 2; i <= lm; i++) {
    if (a % i == 0) {
      tt.push_back(i);
      if (a / i != i) tt.push_back(a / i);
    }
  }
}
int dfs(int len) {
  if (mp.find(len) != mp.end()) return mp[len];
  int ret = mul(2, len - 1) - 1;
  for (int v : tt) {
    if (v >= len) break;
    if (len % v == 0) ret = (ret - dfs(len / v) + 1000000007) % 1000000007;
  }
  return mp[len] = ret;
}
int main() {
  int x, y;
  scanf("%d %d", &x, &y);
  if (y % x != 0) return !printf("0");
  y /= x;
  prime(y);
  sort(tt.begin(), tt.end());
  mp[1] = 1;
  printf("%d", dfs(y));
  return 0;
}
