-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathB.cpp
77 lines (66 loc) · 1.37 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
Author: Zeno_orz
*/
#include <bits/stdc++.h>
using namespace std;
#define FAST ios::sync_with_stdio(0); \
cout.tie(0); \
cin.tie(0);
#define ll long long
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define el "\n"
#define len(x) x.size()
#define ste(v) v.begin(), v.end()
#define stea(arr, n) arr, arr+n
#define vll vector<ll>
#define vpll vector<pair<ll, ll>>
#define vc vector<char>
#define mll map<ll, ll>
#define sll set<ll>
/*----------------Functions---------------*/
void primeSieve(vector<bool> &prime) {
for(ll i=0;i<prime.size();i++) prime[i] = 1;
for (ll i=2;i*i<=prime.size();i++) {
if(prime[i]) {
for(ll j=i*i;j<=prime.size();j+=i) {
prime[j] = 0;
}
}
}
}
/*----------------Functions---------------*/
void solve(){
// Solve here
string a, b;
cin>>a>>b;
// int n=0, m=0;
bool flag = false;
string z = a, y = b;
int m = a.length();
int n = b.length();
int x = (m*n)/(__gcd(m,n));
while(a.length()<x) {
a+=z;
}
while(b.length()<x) {
b+=y;
}
// cout<<flag<<endl;
if(a==b) cout<<a<<endl;
else cout<<-1<<endl;
}
int32_t main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
FAST
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}