Infinite string
InterviewTime limit2sMemory limit512 MB
Given two strings of length at most 50, decide whether each repeated infinitely produces the same infinite string.
- Level
Medium4 of 10
- Topics
- String, String matching
- Solved
- No attempts yet
Problem
For a string , define as the string obtained by concatenating infinitely many times. For example, if is abc, then is abcabcabcabc....
Two different strings and can still give the same and . If is abc and is abcabc, then and are the same string.
Given and , write a program that decides whether and are the same string.
Input
The first line contains and the second line contains . The length of each string is a positive integer at most , and both strings consist of lowercase letters only.
Output
Print on the first line if and are the same, and otherwise.