Cute Common Divisor
InterviewTime limit2sMemory limit512 MB
Given a and b up to 1e9, find a common divisor d whose digit sum is as large as possible, and print any such divisor.
- Level
Medium6 of 10
- Topics
- Number theory, Math, Brute force, Implementation
- Solved
- No attempts yet
Problem
Vasya is very good at counting crows outside the window during math class. Today was an unusual day, since there were a lot of crows. On top of that, there were two kinds: white and black. By the middle of the lesson Vasya finished counting, and outside the window there were white crows and black crows.
Since an unbearably long time remained until the end of the lesson, Vasya decided to listen to what the teacher was saying. At that moment the teacher was explaining what the greatest common divisor of two numbers is. Vasya is a very talented boy and understood it right away. He instantly computed the greatest common divisor of and .
After that he came up with a new term: cute common divisor. Vasya decided to call a positive integer a cute common divisor of and if is divisible by , is divisible by , and the sum of the digits of is maximal.
Help Vasya find the cute common divisor of and .
Input
The only line of the input file contains two integers , ().
Output
Print the cute common divisor of and on the only line of the output file. If there are several answers, you may print any of them.