Least Common Divisor
InterviewTime limit2sMemory limit512 MB
Given two short strings, find the shortest string that divides both, meaning it repeats a whole number of times to form each, or report that none exists.
- Level
Medium4 of 10
- Topics
- String, Math, Number theory, Brute force
- Solved
- No attempts yet
Problem
A divisor of string is a string that can be repeated an integer number of times to obtain . For example, the divisors of the string "aaaa" are "a", "aa", and "aaaa", and the divisors of the string "ababab" are "ab" and "ababab".
Given two strings and , find the shortest string that is both a divisor of and a divisor of , or determine that no such string exists.
Input
The first line contains the string , and the second line contains the string . Each string has length between 1 and 50 characters, inclusive, and consists only of lowercase English letters.
Output
Print the least common divisor of the strings and , or the string "No solution" if the least common divisor does not exist.