-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB.cpp
50 lines (48 loc) · 843 Bytes
/
B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
int gcd(int x,int y)
{
if(y==0)
return x;
else
return gcd(y,x%y);
}
int main()
{
fastio;
int t,n,m,i,f,lcm;
string p,q,a,b;
cin>>t;
while(t--)
{
f=0;
cin>>p;
cin>>q;
a="";
b="";
n=p.size();
m=q.size();
lcm=(n*m)/gcd(n,m);
for(i=0;i<lcm/n;i++)
a.append(p);
for(i=0;i<lcm/m;i++)
b.append(q);
for(i=0;i<lcm;i++)
{
if(a[i]!=b[i])
{
f=1;
break;
}
}
if(f==0)
{
cout<<a<<"\n";
}
else
cout<<"-1"<<"\n";
}
return 0;
}