Big Numbers for Little Vasya
Time limit1sMemory limit1024 MB
Given a digit D repeated N and M times, print the GCD of the two numbers, or its last 10^6 digits if it is longer.
- Level
Medium5 of 10
- Topics
- Math, Number theory, Implementation
- Solved
- No attempts yet
Statement
Vasya received two numbers for his birthday.
The first number is the digit written times in a row. The second number is the same digit written times in a row.
Vasya wanted to find the greatest common divisor of the two numbers, but they are too large for him to compute. Help Vasya find the greatest common divisor of the numbers he received.
The greatest common divisor is the largest natural number that divides both numbers without a remainder.
Input
The first line contains two integers and separated by a space (), the number of digits in the first and second number. The second line contains one integer (), the digit both numbers are made of.
Output
If the decimal representation of the greatest common divisor has at most digits, print the greatest common divisor itself. Otherwise, print its last digits. Do not print leading zeros.