공부기록/백준

[백준] 12871번 무한 문자열

메델 2024. 2. 4. 17:19
import java.util.Scanner;

public class Main {
	
	static int gcd(int a, int b) {
		if(b==0) {
			return a;
		}
		return gcd(b, a%b);
	}
	
	public static void main(String[] args){
		
		Scanner kb = new Scanner(System.in);
		
		String s = kb.next();
		String t = kb.next();
		
		int gcd = gcd(s.length(), t.length());
		String fs = s.repeat(t.length()/gcd);
		String ft = t.repeat(s.length()/gcd);
		
		if(fs.equals(ft)) {
			System.out.println(1);
		}else {
			System.out.println(0);
		}
		
		

	}


}