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

#GL0000353. Đong nước bằng hai bình (Jugs Hard)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đong nước bằng hai bình (Jugs Hard)

Jugs Hard

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

You have two unmarked water jugs of capacities aa and bb and an unlimited water supply. Both jugs are initially empty. One operation may:

  1. Fill either jug completely from the supply.
  2. Empty either jug completely.
  3. Pour from one jug to the other until the source is empty or the destination is full.

Determine whether it is possible to obtain exactly dd units in at least one jug at any time. In particular, d=0d=0 is possible at the start.

PHOJ adaptation: Each file contains a single triple (a,b,d)(a,b,d) instead of multiple original test cases; output remains Yes or No.

Input

A single line with integers a,b,da,b,d.

Output

Yes if possible and No otherwise. Output is case-sensitive.

Subtasks

  • Subtask 1 (20 points): 1<=a,b<=20,0<=d<=max(a,b)1 <= a,b <= 20, 0 <= d <= max(a,b).
  • Subtask 2 (30 points): 1<=a,b<=104,0<=d<=max(a,b)1 <= a,b <= 10^4, 0 <= d <= max(a,b).
  • Subtask 3 (50 points): 1<=a,b<=107,0<=d<=max(a,b)1 <= a,b <= 10^7, 0 <= d <= max(a,b).

Examples

Example 1

Input

8 1 5

Output

Yes

Explanation

The 1-unit jug can repeatedly remove one unit from the 8-unit jug until 5 remain.

Example 2

Input

4 4 3

Output

No

Explanation

The capacities have gcd 4; only multiples of 4 can be measured.

Example 3

Input

5 3 4

Output

Yes

Explanation

Fill the 5-jug, pour into the 3-jug leaving 2; empty the 3-jug, move 2 into it, refill the 5-jug and pour 1 to leave 4.