PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000024. Cộng và nhân để tạo số (Plus and Multiply)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Cộng và nhân để tạo số (Plus and Multiply)

Plus and Multiply

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A set initially contains 11. Whenever xx is in the set, both x⋅ax\cdot a and x+bx+b are included. You may apply the rules repeatedly. Determine whether nn belongs to this set.

Input

One line containing n,a,bn,a,b.

Output

Print Yes if reachable, otherwise No.

Subtasks

  • Subtask 1 (20 points): 1≤n,a,b≤501 \le n,a,b \le 50
  • Subtask 2 (30 points): 1≤n,a,b≤1051 \le n,a,b \le 10^{5}
  • Subtask 3 (50 points): 1≤n,a,b≤1091 \le n,a,b \le 10^{9}

Examples

Input

10 2 3

Output

Yes

Explanation

From 11, multiply by 22 twice to obtain 44, then add 33 twice to reach 1010.