Skip to main content
Back to problems
Codeforces
Easy
Math
Number Theory
Cifera

Determine whether one number is a power multiple of another by repeatedly multiplying and checking divisibility.

Acceptance 0%
Problem Statement

Problem

You are given two positive integers aa and bb. Determine whether there exists a non-negative integer kk such that

b=akb = a^k

If such a kk exists, the numbers are related; otherwise, they are not.

In practice, this means you should verify whether bb can be obtained by starting from aa and repeatedly multiplying by aa until reaching bb exactly.

Input Format

  • The first line contains two integers aa and bb.

Output Format

  • Print YES if bb is a power of aa.
  • Otherwise, print NO.

Constraints

  • 1a,b1091 \le a, b \le 10^9

Hints

  • Repeatedly divide bb by aa while it is divisible.
  • If the process ends at $1,then, then bwasapowerofwas a power ofa$.

Input Format

  • One line with two integers aa and bb.

Output Format

  • Output YES if bb is a power of $a, otherwise output NO`.

Constraints

  • 1a,b1091 \le a, b \le 10^9
Examples
Sample cases returned by the problem API.

Example 1

Input

2 8

Output

YES

Explanation

Since 8=238 = 2^3, the answer is YES.

Example 2

Input

3 10

Output

NO

Explanation

No integer power of $3 equals \10`.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.