solution stringlengths 11 983k | difficulty int64 0 21 | language stringclasses 2
values |
|---|---|---|
a,b=map(int,input().split())
c,d=map(int,input().split())
while b!=d and max(b,d)<pow(10,4)+1:
if b<d:b+=a
else:d+=c
if b==d:print(b)
else:print(-1) | 7 | PYTHON3 |
import sys
a, b = map(int, input().split())
c, d = map(int, input().split())
times1 = [b + a*i for i in range(100)]
for time2 in [d + c*i for i in range(100)]:
if time2 in times1:
print(time2)
sys.exit()
print(-1)
| 7 | PYTHON3 |
a,b=map(int,input().split())
c,d=map(int,input().split())
f=0
for i in range(0,101):
for j in range(0,101):
if(b+i*a==d+j*c):
print(b+i*a)
f=1
break
if(f==1):
break
if(f==0):
print(-1)
| 7 | PYTHON3 |
import sys
a, b = map(int, input().split())
c, d = map(int, input().split())
cur1, cur2 = b, d
x = set()
y = set()
for i in range(100000):
x.add(cur1)
y.add(cur2)
cur1 += a
cur2 += c
for i in range(100000):
if i in x and i in y:
print(i)
sys.exit(0)
print(-1)
| 7 | PYTHON3 |
# -*- coding: utf-8 -*-
st = input()
i = 0
n = ''
m = ''
while st[i] != " ":
n = n + st[i]
i += 1
i += 1
while i < len(st):
m = m + st[i]
i += 1
a = int(n)
b = int(m)
st = input()
i = 0
n = ''
m = ''
while st[i] != " ":
n = n + st[i]
i += 1
i += 1
while i < len(st):
m = m + st[i]
i += ... | 7 | PYTHON3 |
a, b = map(int, input().split())
c, d = map(int, input().split())
"""
def nok(a, b):
r = a
while r % b != 0:
r += a
return r
def get_answer():
if b == d:
return 0
if c == a:
return -1
if (b - d) * (c - a) < 0:
return -1
k = nok(abs(b - d), abs(c - a))
... | 7 | PYTHON3 |
x,y=map(int,input().split())
p,q=map(int,input().split())
for i in range(1,101):
for j in range(1,101):
if (y+(i-1)*x)==(q+(j-1)*p):
print(y+(i-1)*x)
exit()
print(-1) | 7 | PYTHON3 |
x,y=map(int,input().split())
z,t=map(int,input().split())
tmp=0
def timluot(a,b,c,d):
i=0
tm=0
while i<=200:
j=0
tm=b+a*i
while True:
tmp=d+c*j
if tmp==tm:
return tmp
elif tmp>tm:
break
j+=1
i+=1... | 7 | PYTHON3 |
a,b = list(map(int, input().split()))
c,d = list(map(int, input().split()))
check=-1
#print("A")
for i in range(101):
for j in range(101):
if b+i*a==d+j*c:
check=1
print(b+i*a)
break
if check==1:
break
if check==-1:
print("-1") | 7 | PYTHON3 |
a, b = map(int, input().split())
c, d = map(int, input().split())
ans = -1
for i in range(int(1e6)):
if b < d:
b += a
elif d < b:
d += c
else:
ans = d
break
print(ans) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long ar[500005];
long long br[500005];
int main() {
long long a, b, c, d, i, j, k, m, n, t, sum, f;
cin >> a >> b;
cin >> c >> d;
for (i = 0; i < 101; i++) ar[i] = b + i * a;
for (i = 0; i < 101; i++) br[i] = d + i * c;
for (i = 0; i < 101; i++)
for (j ... | 7 | CPP |
a, b = list(map(int, input().split()))
c, d = list(map(int, input().split()))
t1 = b
t2 = d
solution_found = False
for i in range(10000):
if (t1 == t2):
print(t1)
solution_found = True
break
elif (t1 > t2):
t2 += c
else:
t1 += a
if (not solution_found):
print(-1) | 7 | PYTHON3 |
a, b = map(int, input().split())
c, d = map(int, input().split())
same_time = 0
coeff = 0
count = 0
if (a % 2 == 0 and b % 2 != 0) and c % 2 == 0 and d % 2 == 0:
print("-1")
elif (a % 2 == 0 and b % 2 == 0) and c % 2 == 0 and d % 2 != 0:
print("-1")
elif b == d:
print(b)
else:
if b > d:
g =... | 7 | PYTHON3 |
flag=1
a,b=map(int,input().split())
c,d=map(int,input().split())
for i in range(1,1000):
if flag==1:
for j in range(1,1000):
if b+a*i-a-d-c*j+c==0:
print(b+(i-1)*a)
flag=0
break
else:
break
if flag==1:
print("-1")
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int i = 0, n, a, b = 0, c = 0, e, m, d, t = 0, x, sum = 0, y, f = 0,
o, z = 0, h = 0, l = 0, k = 0, r, x1, x2, y1, y2;
cin >> a >> b;
cin >> c >> d;
for (i = 0; i < 100000; i++) {
if (b == d) {
cout << b;
z = 1;... | 7 | CPP |
b, a = map(int, input().split())
d, c = map(int, input().split())
if a < c:
a, b, c, d = c, d, a, b
R = [a+i*b for i in range(d) if (a+i*b - c) % d == 0]
if R:
print(min(R))
else:
print(-1)
| 7 | PYTHON3 |
a, b = map(int, input().split())
c, d = map(int, input().split())
checker = False
for i in range(100):
for k in range(100):
if b+i*a == d+k*c:
print(b+i*a)
checker = True
if checker: break
if checker: break
if not checker:
print("-1") | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, e[10100], f[10100], i, j;
cin >> a >> b;
cin >> c >> d;
for (i = 0; i < 100; i++) {
e[i] = b + i * a;
for (j = 0; j < 100; j++) {
f[j] = d + j * c;
if (e[i] == f[j]) {
cout << e[i] << endl;
return 0;
... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000001;
using ll = long long;
using ull = unsigned long long;
struct ToggleSeparator {};
template <ostream *Out>
struct DumpFirst {};
template <ostream *Out>
struct Dumper {
static void *&last() {
static void *p;
return p;
}
static const ch... | 7 | CPP |
a,b=map(int,input().split())
c,d=map(int,input().split())
ans=-1
for i in range(1,101):
x=b+(i-1)*a
for j in range(1,101):
y=d+(j-1)*c
if(y==x):
ans=y
print(ans)
quit(0)
if(y>x):
break
print(ans) | 7 | PYTHON3 |
b,a = map(int,input().split())
d,c = map(int,input().split())
ans = -1
ar = [a+b*i for i in range(100)]
br = [c+d*i for i in range(100)]
i = 0
j = 0
while i<100 and j<100:
if ar[i]==br[j]:
ans = ar[i]
break
elif ar[i]<br[j]:
i+=1
else:
j+=1
print(ans) | 7 | PYTHON3 |
a, b = map(int, input().split())
c, d = map(int, input().split())
ans = -1
dic = {}
for i in range(200):
dic[b + a*i] = 1
for i in range(200):
if d + i*c in dic:
print(d + i*c)
break
else:
print(-1) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5 + 9;
const int INF = 1e9 + 5;
const int mod = 1e9;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
set<int> kek;
for (int i = 0; i < 1e5; i++) {
kek.insert(b + a * i);
}
for (int i = 0; i < 1e5; i++)
if (kek.find(d + c * i) !=... | 7 | CPP |
a,b=input().split(" ")
c,d=input().split(" ")
a=int(a)
b=int(b)
c=int(c)
d=int(d)
s=b
s1=d
j=0
if(not (a&(a-1)==a-1) and not (c&(c-1)==c-1)):
if(b&(b-1)==b-1 and not (d&(d-1)==d-1)):
print("-1")
j=1
while(j==0 and s<100000):
if(s==s1):
print(s)
j=1
elif(s1>s):
... | 7 | PYTHON3 |
# -*- coding: utf-8 -*-
"""
Created on Sun Dec 16 12:35:38 2018
@author: asus
"""
a,b=(int(x) for x in input().split())
c,d=(int(x) for x in input().split())
while b!=d and b<10**4:
if b<d:
b+=a
else:
d+=c
if b!=d:
print(-1)
else:
print(b) | 7 | PYTHON3 |
def compute_gcd(a, b):
if a == 0:
return b
return compute_gcd(b % a, a)
def main():
a, b = map(int, input().split())
c, d = map(int, input().split())
gcd = compute_gcd(a, c)
if (b - d) % gcd != 0:
print(-1)
steps = 1000
size = max(b, d) + max(a, c) * steps
used =... | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, a, b, c, d;
bool ok = false;
cin >> a >> b >> c >> d;
for (i = 0; i <= 100; ++i) {
int dif = b - d + i * (a - c);
if (dif % c == 0 && i * a + b >= d) {
ok = true;
break;
}
}
if (ok == true)
cout << i * a + b;
els... | 7 | CPP |
ab = list(map(int, input().split()))
a = ab[0]
b = ab[1]
cd = list(map(int, input().split()))
c = cd[0]
d = cd[1]
list1 = []
list2 = []
counter1= 0
counter2 = 0
for i in range(max(a + b,c + d)):
list1.append(counter1 * a + b)
list2.append((counter2 * c + d))
counter1 += 1
counter2 += 1
for i in range... | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, i, j, flag = 0;
scanf("%d %d %d %d", &a, &b, &c, &d);
for (i = 0; i <= 100; i++)
for (j = 0; j <= 100; j++) {
if (b + a * i == d + c * j) {
printf("%d", b + a * i);
return 0;
}
}
if (flag == 0) printf(... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
double n;
cin >> a >> b;
cin >> c >> d;
if (b == d) {
cout << b << endl;
return 0;
}
for (int i = 0; i <= 100000; i++) {
n = 1.00 * ((d - b) + c * i) / a;
if (ceil(n) == floor(n) && n >= 0) {
cout << (int)(b +... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
int a, b, c, d;
cin >> a >> b >> c >> d;
if (b <= d) {
unsigned long long k = 0, x = d;
d -= b;
d %= a;
vector<bool> arr(a, false);
while (!arr[d] && d != 0) {
k++;
arr[d] = true;
d ... | 7 | CPP |
import math
def bezout(m,n,t):
x=0
while((t-m*x)%n!=0):
x+=1
return (x,int(t-m*x)/n)
a,b=map(int,input().split())
c,d=map(int,input().split())
if (d-b)%(math.gcd(a,c)) !=0:
print(-1)
else:
(t1,t2)=bezout(a,c,d-b)
while(t2>0):
t1+=int(c/math.gcd(a,c))
t2-=int(a/math.gcd(a,... | 7 | PYTHON3 |
gcd = lambda a, b: gcd(b, a % b) if b else a
a, b = map(int, input().split())
c, d = map(int, input().split())
if (d - b) % gcd(a, c):
print(-1)
else:
while True:
if b == d:
print(b)
break
if b < d:
b += a
else:
d += c | 7 | PYTHON3 |
import collections
a,b=map(int,input().split())
c,d=map(int,input().split())
v=collections.defaultdict(int)
i=0
while True:
if b-d>0:
if ((b-d)+a*i)%c==0:
print(b+a*i)
break
if v[((b-d)+a*i)%c] not in v:
v[((b-d)+a*i)%c]+=1
else:
print(-1)
... | 7 | PYTHON3 |
a, b = map(int, input().split())
c, d = map(int, input().split())
e = []
g = []
l = 0
for i in range(101):
h = b+i*a
e.append(h)
k = d+i*c
g.append(k)
#print(e)
#print(g)
for i in range(len(e)):
if e[i] in g:
l = 1
s = e[i]
break
if(l == 1):
print(e[i])
else:
print(-1... | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, mn = -111111;
int main() {
ios_base::sync_with_stdio(0);
cin >> a >> b >> c >> d;
for (long long i = 0; i <= 4000; i++) {
for (long long j = 0; j <= 4000; j++) {
if (b + i * a == d + j * c) {
if (mn == -111111) {
mn = ... | 7 | CPP |
import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97 # a
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return [int(i) for i in input().split()]
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def rev... | 7 | PYTHON3 |
import sys
input = sys.stdin.readline
a, b = map(int, input().split())
c, d = map(int, input().split())
found = False
for i in range(int(1e6)):
j = (a*i + b - d)/c
if j % 1 == 0 and j >= 0:
print(a*i + b)
found = True
break
if not found:
print(-1) | 7 | PYTHON3 |
a, b = [int(v) for v in input().split(' ')]
c, d = [int(v) for v in input().split(' ')]
# Il ragionamento qui è che dobbiamo imporre
# b + ai = d + cj
# che è un'eq. diofantea che ha soluzione sse gcd(c, a) | (d - b) -- [Hardy & Wright, An introduction to the theory of numbers, thm.25]
# siccome inoltre a, b, c e d so... | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
long long a, b, c, d;
cin >> a;
cin >> b;
cin >> c;
cin >> d;
long long z = abs(d - b);
long long e = gcd(a, c);
if (z % e != 0)
cout << -1;
else {... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (abs(b - d) % gcd(a, c)) {
cout << -1;
return 0;
}
int x = b;
while (1) {
if ((x - d) >= 0 && (x - d) % c == 0) {
... | 7 | CPP |
a,b=map(int,input().split())
c,d=map(int,input().split())
l1=[]
l2=[]
for i in range(0,1000):
l1.append(b+i*a)
for j in range(0,1000):
if (d+c*j) in l1:
print(d+c*j)
break
else:
print(-1)
| 7 | PYTHON3 |
g=lambda x,y:g(y,x%y)if y else x
a,b=map(int,input().split())
c,d=map(int,input().split())
e=g(a,c)
if (b-d)% e:print(-1)
else:
while b!=d:
if b<d:b+=a
else:d+=c
print(b)
| 7 | PYTHON3 |
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
a, b = map(int, input().split())
c, d = map(int, input().split())
morty = set()
cr = b
for i in range(1000):
morty.add(cr)
cr += a
cr = d
for i in range(1000):
if cr in morty:
print(cr)
exit(0)
cr += c
print(-1)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
int a1 = 0;
int a2 = 0;
int R, M;
int cnt = 0, flag = 1;
while (1) {
if (cnt > 1e7) {
flag = 0;
break;
}
R = b + a1 * a;
M = d + a2 * c;
if (R > M) a2++;
if (R < M) a1++;... | 7 | CPP |
arr = input().split(' ')
a = int(arr[0])
b = int(arr[1])
arr = input().split(' ')
c = int(arr[0])
d = int(arr[1])
k = set(range(b,10**4,a))
l = set(range(d,10**4,c))
j = k & l
print(min(j) if j else -1)
| 7 | PYTHON3 |
a, b = map(int, input().split())
c, d = map(int, input().split())
for x in range(101):
y = (b + a*x - d) * 1.0/c
if y % 1 == 0 and y >= 0:
print (b+a*x)
exit()
print ("-1")
| 7 | PYTHON3 |
import sys
a, b = [int(x) for x in input().split()]
c, d = [int(x) for x in input().split()]
if a < c:
b, a, d, c = d, c, b, a
foundoverlap = False
x = b
while x < 100000:
if x < d:
x = x + a
continue
if (x - d) % c == 0:
print(x)
foundoverlap = True
break
x = ... | 7 | PYTHON3 |
a,b=map(int,input().split())
r,l=map(int,input().split())
for i in range(0,101) :
for j in range(101) :
if a*i+b==l+r*j :
print(a*i+b)
exit()
print(-1)
| 7 | PYTHON3 |
######### ## ## ## #### ##### ## # ## # ##
# # # # # # # # # # # # # # # # # # #
# # # # ### # # # # # # # # # # # #
# ##### # # # # ### # # # # # # # # #####
# # # # # # # # # # # # # # # # # #
#########... | 7 | PYTHON3 |
a,b = map(int,input().split())
c,d = map(int,input().split())
res = -1
for i in range(10000):
if (b+a*i-d) % c == 0 and b+a*i-d >= 0:
res = b+a*i
break
print(res) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000009;
map<long long int, int> m;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
for (int i = 0; i < 100000; i++) {
m[b + i * a] = 1;
}
for (int i = 0; i < 100000; i++) {
if (m[d + i * c] == 1) {
cout << d + i * ... | 7 | CPP |
#!/usr/bin/env python3
from fractions import gcd
def ri():
return map(int, input().split())
a, b = ri()
c, d = ri()
if c > a:
a, c = c, a
b, d = d, b
for i in range(10**5):
if b-d+i*a >=0 and (b-d+i*a)%c == 0:
print(b+i*a)
exit()
else:
print(-1) | 7 | PYTHON3 |
from fractions import gcd
a, b = [int(x) for x in input().split()]
c, d = [int(x) for x in input().split()]
g = gcd(a, c)
if abs(b - d) % g != 0:
print(-1)
else:
s1 = set([b])
s2 = set([d])
while True:
if b in s2:
print(b)
break
if d in s1:
print(d)
... | 7 | PYTHON3 |
(a, b) = (int(i) for i in input().split())
(c, d) = (int(i) for i in input().split())
br = -1
for k in range(1000000):
n = ((d-b+c*k)/a)
if n>=0 and not n%1:
br = k
break
if br!=-1:
print(d+c*br)
else:
print(-1) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int ans = -1;
map<int, int> m;
int a, b, c, d;
cin >> a >> b >> c >> d;
m[b]++;
m[b + a]++;
for (int i = 2; i <= 100; ++i) {
m[(i * a) + b]++;
}
if (m[d] == 1)
ans = d;
else if (m[d + c] == 1)
ans = d + c;
else {
for (int... | 7 | CPP |
a,b=map(int,input().split())
c,d=map(int,input().split())
x=y=0
chk=set([])
for i in range(0,700000,1):
x=b+a*i
y=d+c*i
if x==y or (x in chk and y in chk):
print(min(x,y))
exit()
if x in chk:
print(x)
exit()
if y in chk:
print(y)
exit()
chk.add(x)
... | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, e, f, cs = 10000;
cin >> a >> b >> c >> d;
e = b;
f = d;
for (cs; cs > 0; cs--) {
if (e < f)
e += a;
else if (e > f)
f += c;
else if (e == f)
break;
}
if (cs == 0) {
cout << "-1\n";
return 0;
... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int a, b, c, d;
int main() {
scanf("%d%d%d%d", &a, &b, &c, &d);
for (int i = max(b, d); i < 100000; i++) {
if ((i - b) % a == 0 && (i - d) % c == 0) {
printf("%d", i);
return 0;
}
}
printf("-1");
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i, j, k, l, m, t, a, b, c, d;
string str;
cin >> a >> b;
cin >> c >> d;
long long count1 = 0;
bool flag = 0;
while (count1 <= 20000) {
while (b < d) {
b += a;
count1++;
}
while (d < b) {
d += c;
cou... | 7 | CPP |
a, b = map(int, input().split())
c, d = map(int, input().split())
# b + ai = d + cj
# -> i = (d - b + cj) / a
cnt = 0
founded = False
j = 0
while cnt <= a:
i = (d - b + c*j) // a
if i >= 0:
cnt += 1
if (d - b + c*j) % a == 0:
founded = True
break
j += 1
if founded:
print(b + a*i)
else:
p... | 7 | PYTHON3 |
a,b = map(int, input().split())
c, d = map(int, input().split())
#ax - cy = d- b
def GCD(a,b):
while b != 0:
r = a % b
a = b
b = r
return a
if (d - b) % GCD(a,c) != 0:
print(-1)
else:
y = 0
while True:
x = (d - b + c*y) // a
if x >= 0 and (d - b + c*y) % a =... | 7 | PYTHON3 |
a, b = map(int, input().split())
c, d = map(int, input().split())
while (b!=d and b<10**5):
if b<d:
b+=a
else:
d+=c
if (b==d):
print(b)
else:
print(-1) | 7 | PYTHON3 |
a,b = map(int,input().split())
c,d = map(int,input().split())
def rick(a,b,r):
return b+a*r
def morty(c,d,r):
return d+c*r
def gcd(a,b):
if b==0:
return a
return gcd(b,a%b)
pos = d-b
if (pos % gcd(a,c) !=0):
print(-1)
else:
i = 0
j = 0
while True:
if rick(a,b,i) < morty... | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
const long long int MAXN = 2e5 + 5;
const long long int mod = 1000000007;
const long long int N = 200005;
void solve() {
int a, b, c, d;
cin >> a >> b >> c >> d;
map<int, int> mp;
int dis1 = b, dis2 = ... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, d1;
int b, d2, i;
cin >> d1 >> a >> d2 >> b;
int n, m, KK;
KK = max(max(a, b), max(d1, d2));
n = 0;
while (true) {
if (n > KK) {
cout << -1;
return 0;
}
m = 0;
while ((b + m * d2) < (a + n * d1)) m++;
if ((b ... | 7 | CPP |
'''input
69 48
39 9
'''
a, b = map(int, input().split())
c, d = map(int, input().split())
# if (b % 2 != d % 2 and a % 2 == c % 2):
# print(-1)
# else:
for x in range(100):
for y in range(100):
if b + x*a == d + y*c:
print(b + x*a)
quit()
print(-1)
| 7 | PYTHON3 |
a, b = map(int, input().split())
c, d = map(int, input().split())
ans = 1e18
for i in range(1000):
for j in range(1000):
if b + a*i == d + c*j:
ans = min(ans, b + a*i)
if ans == 1e18:
ans = -1
print(ans) | 7 | PYTHON3 |
import sys
a,b = map(int,input().split())
c,d = map(int,input().split())
li = []
li1 = []
for i in range(100):
for j in range(100):
if (b+a*i == d+c*j):
print(b+a*i)
sys.exit()
print("-1")
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d;
int main() {
cin >> a >> b >> c >> d;
while (b != d and b < 1000000) {
if (b < d)
b = b + a;
else
d = d + c;
}
if (b < 100000)
cout << b;
else
cout << "-1";
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a = 0, b = 0, c = 0, d = 0, res = INT_MAX;
cin >> a >> b;
cin >> c >> d;
for (int i = 0; i <= 100; ++i)
for (int j = 0; j <= 100; ++j) {
if (b + i * a == d + j *... | 7 | CPP |
from math import gcd
def main():
a, b = map(int, input().split())
c, d = map(int, input().split())
n = a * c // gcd(a, c) + b + d
l = [*[0] * n, 2]
for i in range(b, n, a):
l[i] = 1
for i in range(d, n, c):
l[i] += 1
i = l.index(2)
print(i if i < n else -1)
if __name_... | 7 | PYTHON3 |
#include <bits/stdc++.h>
int v[1000001];
using namespace std;
int main() {
int a, b, c, d;
scanf("%d%d%d%d", &a, &b, &c, &d);
while (b <= 1000000) {
v[b] = 1;
b += a;
}
while (d <= 1000000) {
if (v[d] == 1) {
printf("%d", d);
return 0;
}
d += c;
}
printf("-1");
return 0;
... | 7 | CPP |
a,b = map(int,input().split())
c,d = map(int,input().split())
f = []
s = []
ans = -1
for i in range(10000):
ff = b+(i*a)
f.append(ff)
for i in range(10000):
ss = d+(i*c)
if(ss in f):
ans = ss
break
s.append(ss)
print(ans)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 900010;
int a, b, c, d;
int main() {
cin >> a >> b;
cin >> c >> d;
if (b == d) {
return 0 * printf("%d\n", b);
} else {
for (int i = 0; i <= 1000; i++)
for (int j = 0; j <= 1000; j++) {
if (b + i * a == d + j * c) {
retu... | 7 | CPP |
#include <bits/stdc++.h>
int main(void) {
int a, b, c, d, i;
scanf("%d%d%d%d", &a, &b, &c, &d);
for (i = 1; i <= 10000000; i++) {
if (i - b < 0 || i - d < 0) continue;
if ((i - b) % a == 0 && (i - d) % c == 0) {
printf("%d\n", i);
return 0;
}
}
printf("-1\n");
return 0;
}
| 7 | CPP |
a,b=[int(i)for i in input().split()]
c,d=[int(i)for i in input().split()]
ans=-1
for i in range(int(1e6)):
if b<d:b+=a
elif d<b:d+=c
else:ans=d;break
print(ans) | 7 | PYTHON3 |
##n = int(input())
##a = list(map(int, input().split()))
##print(' '.join(map(str, res)))
[a, b] = list(map(int, input().split()))
[c, d] = list(map(int, input().split()))
def gcd(a, b):
if b == 0:
return a
return gcd(b, a%b);
if abs(d-b)%gcd(a, c) != 0:
print('-1')
exit(0)
res = 1000000
for... | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, e;
scanf("%d %d", &a, &b);
scanf("%d %d", &c, &d);
if (d > b) {
int t = a;
a = c;
c = t;
t = b;
b = d;
d = t;
}
int i;
for (i = 0; i < 1000; i++) {
int t = (a * i + b - d) % c;
if (t == 0) {
pr... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
scanf("%d %d", &a, &b);
scanf("%d %d", &c, &d);
for (int i = 0; i < 1e6 + 100; i++) {
int t = b + i * a;
if (t - d >= 0 && (t - d) % c == 0) {
printf("%d\n", t);
return 0;
}
}
printf("-1\n");
return 0;
}
| 7 | CPP |
def e_gcd(a,b):
s = pt = 0
ps = t = 1
r = b
pr = a
while r:
q = pr // r
pr, r = r, (pr - q*r)
ps, s = s, (ps - q*s)
pt, t = t, (pt - q*t)
return pr, (ps, pt)
a, b = [int(x) for x in input().split()]
c, d = [int(x) for x in input().split()]
g, x = e_gcd(a,c)
num ... | 7 | PYTHON3 |
def find_scream():
a, b = map(int, input().split())
c, d = map(int, input().split())
for i in range(0, 1000):
current_scream = b + a * i
if (current_scream - d ) % c == 0 and current_scream - d >= 0:
print(current_scream)
return
print(-1)
return
find_scream... | 7 | PYTHON3 |
a, b = map(int, input().split())
c, d = map(int, input().split())
ans = -1
for i in range(100000):
if b == d:
ans = b
break
elif b < d:
b += a
else:
d += c
print(ans) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
for (int i = 1; i <= 100; i++) {
for (int j = 1; j <= 100; j++) {
if (((i - 1) * a) + b == ((j - 1) * c) + d) {
cout << ((i - 1) * a) + b;
return 0;
}
}
}
cout << -1;
}
| 7 | CPP |
## necessary imports
import sys
input = sys.stdin.readline
from math import log2, log, ceil
# swap_array function
def swaparr(arr, a,b):
temp = arr[a];
arr[a] = arr[b];
arr[b] = temp
## gcd function
def gcd(a,b):
if a == 0:
return b
return gcd(b%a, a)
## nCr function efficient using Binom... | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, i, j;
int NOD(int x, int y) {
while (x > 0 && y > 0) {
if (x > y) {
x %= y;
} else {
y %= x;
}
}
return x + y;
}
int main() {
scanf("%d%d%d%d", &a, &b, &c, &d);
if ((b - d) % NOD(a, c) != 0) {
printf("-1");
return 0;... | 7 | CPP |
#include <bits/stdc++.h>
std::pair<std::pair<int, int>, int> gcd(int a, int b) {
if (b == 0) {
return std::make_pair(std::make_pair(1, 0), a);
} else {
int c = a % b;
int mult = (a - c) / b;
std::pair<std::pair<int, int>, int> res = gcd(b, c);
return std::make_pair(
std::make_pair(res.fi... | 7 | CPP |
a, b = map(int, input().split())
c, d = map(int, input().split())
arr = [b + a * i for i in range(1000)]
for i in range(1000):
if d + c * i in arr:
print(d + c * i)
exit()
print(-1)
| 7 | PYTHON3 |
def BS(f,n,len):
L = 0
R = len-1
while(L<=R):
mid = (L+R)//2
if(f[mid] == n):
return True
elif(f[mid]<n):
L =(mid+1)
else:
R =(mid-1)
return False
a,b = map(int,input().split())
c,d = map(int,input().split())
f = []
s = []
ans = -1
for i in range(10000):
ff = b+(i*a)
f.append(ff)
size = len(f)... | 7 | PYTHON3 |
inputBuffer = input().split()
a = int(inputBuffer[0])
b = int(inputBuffer[1])
inputBuffer = input().split()
c = int(inputBuffer[0])
d = int(inputBuffer[1])
ans = 1E9
for i in range(1000):
for j in range(1000):
if (a*i+b == c*j+d):
ans = min(ans,a*i+b)
if (ans == 1E9):
ans = -1
print(ans... | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
scanf("%d %d %d %d", &a, &b, &c, &d);
vector<bool> can(1e7 + 1);
for (int i = b; i <= 1e7; i += a) {
can[i] = true;
}
for (int i = d; i <= 1e7; i += c) {
if (can[i]) {
printf("%d\n", i);
return 0;
}
}
prin... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int rick, morty;
int a, b, c, d, x, y;
int main() {
cin >> a >> b >> c >> d;
for (x = 0, y = 0; x <= 100 && y <= 100;) {
rick = b + x * a;
morty = d + y * c;
if (rick == morty) {
cout << rick;
return 0;
}
if (rick > morty)
y++;
... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
unsigned long long cream_time(unsigned long long in1, unsigned long long int2,
unsigned long long time);
int main() {
unsigned long long a = 0, b = 0, c = 0, d = 0;
unsigned long long catched_time = 0, cream_count = 0;
unsigned long long ... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long i, a, b, c, d, mn, mx;
cin >> a >> b >> c >> d;
mn = min(b, d);
b -= mn;
d -= mn;
if (d > b) {
for (i = 0; i < 1000; i++) {
if (d % a == 0) {
cout << d + mn;
return 0;
}
d += c;
}
} else if (d < ... | 7 | CPP |
a,b=map(int,input().split())
c,d=map(int,input().split())
s={b-d}
while b!=d:
if b<d: b+=a
else: d+=c
bd=b-d
if bd in s: break
s|={bd}
if d==b: print(b)
else: print(-1) | 7 | PYTHON3 |
a, b = [int(v) for v in input().split(' ')]
c, d = [int(v) for v in input().split(' ')]
# Il ragionamento qui è che dobbiamo imporre
# b + ai = d + cj
# che è un'eq. diofantea che ha soluzione sse gcd(c, a) | (d - b) -- [Hardy & Wright, An introduction to the theory of numbers, thm.25]
# siccome inoltre a, b, c e d so... | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int dp[199];
int main() {
long long x, y, x1, y1;
int untd = -1;
cin >> x >> y;
cin >> x1 >> y1;
for (int k = 0; k <= 100; k++)
for (int j = 0; j <= 100; j++)
if (y + x * k == y1 + x1 * j) {
cout << y + x * k;
return 0;
}
cout << ... | 7 | CPP |
a, b = map(int,input().split())
c, d = map(int,input().split())
cnt = 0
found = False
j = 0
while cnt <= a:
i = (d-b + c *j)//a
if i >= 0:
cnt += 1
if (d-b+c*j)%a == 0:
found = True
# print (i,j)
break
j += 1
if found:
print (b+a*i)
else:
prin... | 7 | PYTHON3 |
R = lambda:map(int , input().split())
a , b = R()
c , d = R()
n = 100000
f = [0] * n
i = b
while(i < 10000 ) :
f[i] |= 1
i += a
i = d
while(i < 10000 ) :
f[i] |= 2
i += c
found = False
i = 0
while(i < 10000) :
if f[i] == 3 :
print(i)
found = True
break
i += 1
if(n... | 7 | PYTHON3 |
a, b = map(int,input().split()) #b + a, b + 2a
c, d = map(int,input().split()) #c + d, c + 2d
e = [b]
f = [d]
g = 1
h = 0
for i in range(0, 5000):
x = b + g * a
e.append(x)
y = d + g * c
f.append(y)
g += 1
u = set(e)
i = set(f)
y = u&i
if y:
print(min(y))
else:
print("-1")
| 7 | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.