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

#GL0000047. UCLN của số nhỏ và số thập phân cực lớn (GCD2)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

UCLN của số nhỏ và số thập phân cực lớn (GCD2)

GCD2

Source: SPOJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given nonnegative integers A,BA,B, where AA is small and BB may contain very many decimal digits, compute gcd⁡(A,B)\gcd(A,B) exactly without parsing BB as a built-in integer. When A=0A=0, the answer is BB. If both integers are zero, define the result to be 00.

Input

One line contains AA and the decimal representation of BB.

Output

Print the GCD as a decimal integer.

Subtasks

  • Subtask 1 (20 points): 0≤A≤1000 \le A \le 100; A≤B<1015A \le B < 10^{15}
  • Subtask 2 (30 points): 0≤A≤100000 \le A \le 10000; A≤B<10100A \le B < 10^{100}
  • Subtask 3 (50 points): 0≤A≤400000 \le A \le 40000; A≤B<10250A \le B < 10^{250}

Examples

Input

10 11

Output

1

Explanation

Since 11 mod 10=111\bmod10=1, we obtain gcd⁡(10,11)=1\gcd(10,11)=1.