/* -*- coding: utf-8 -*- * * 2954.cc: No.2954 Calculation of Exponentiation - yukicoder */ #include #include #include #include using namespace std; /* typedef */ using pii = pair; /* subroutines */ template T gcd(T m, T n) { // m >= 0, n >= 0 if (m < n) swap(m, n); while (n > 0) { T r = m % n; m = n; n = r; } return m; } pii readrat() { char s[32]; scanf("%s", s); char *cpt = s; int sign = 1; if (*cpt == '-') sign = -1, cpt++; int p = 0, q = 0; while (*cpt >= '0' && *cpt <= '9') p = p * 10 + (*(cpt++) - '0'); cpt++; // '.' while (*cpt >= '0' && *cpt <= '9') q = q * 10 + (*(cpt++) - '0'); int n = p * 10000 + q, d = 10000; int g = gcd(n, d); n /= g, d /= g; return {n * sign, d}; } /* main */ int main() { auto [an, ad] = readrat(); auto [bn, bd] = readrat(); if (bn == 0) { puts("Yes"); return 0; } if (bn < 0) { swap(an, ad); bn = -bn; } //printf(" a=%d/%d, b=%d/%d\n", an, ad, bn, bd); if (ad == 1) { if (bd == 1) { puts("Yes"); return 0; } int x0 = 1, x1 = an + 1; while (x0 + 1 < x1) { int x = (x0 + x1) / 2; if (pow(x, bd) > an) x1 = x; else x0 = x; } if (pow(x0, bd) == an) { puts("Yes"); return 0; } } puts("No"); return 0; }