Checking if A^n == B^m for strings A,B and any n,m