solution stringlengths 11 983k | difficulty int64 0 21 | language stringclasses 2
values |
|---|---|---|
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, SZ = 1e5 + 5;
int dx[4] = {-1, 0, 0, 1};
int dy[4] = {0, -1, 1, 0};
int dxx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dyy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int main() {
int i, j, fl = 0;
int a, b, c, d, m, n, tmp;
cin >> a >> b >> c >> d;
tmp = ... | 7 | CPP |
from sys import maxsize, stdout, stdin, stderr
# mod = int(1e9 + 7)
#import re # can use multiple splits
tup = lambda: map(int, stdin.readline().split())
I = lambda: int(stdin.readline())
lint = lambda: [int(x) for x in stdin.readline().split()]
S = lambda: stdin.readline().replace('\n', '').strip()
#def grid(r, c): re... | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int n, i, j;
long long int a1, b1, c1, d1;
map<long long int, long long int> ma;
cin >> a1 >> b1;
cin >> c1 >> d1;
for (i = 0; i < 1000006; i++) {
ma[b1 + i * a1] = 1;
... | 7 | CPP |
a,b=[int(i) for i in input().split()]
c,d=[int(i) for i in input().split()]
for i in range(0,10000):
if b+a*i>=d and (b+a*i-d)%c==0:
print(b+a*i)
exit(0)
print(-1)
| 7 | PYTHON3 |
import sys,math,io,os,time,itertools,collections
mod=10**9+7
sys.setrecursionlimit(10000)
i=sys.stdin.readline
p=sys.stdout.write
#use sys.stdout.write() (remember to convert to str b4 and concatenate "\n")
global start,end
#binary search
def isin(l,x):
left=0
right=len(l)-1
if x<l[0]:
return -1
... | 7 | PYTHON3 |
a, b = [int(i) for i in input().split()]
c, d = [int(i) for i in input().split()]
res = [0 for i in range(10000000)]
for i in range(10000):
res[int(b + a*i)] = 1
for i in range(10000):
if res[d + c*i] == 1:
print(d+c*i)
exit()
print(-1) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int g, x, y;
void e_gcd(int a, int b, int &g, int &x, int &y) {
if (!b) {
x = 1;
y = 0;
g = a;
} else {
e_gcd(b, a % b, g, y, x);
y -= a / b * x;
}
}
int main() {
int a, b, c, d;
scanf("%d%d%d%d", &a, &b, &c, &d);
int tmp = d - b;
e_gcd(a, ... | 7 | CPP |
import math
a, b = map(int, input().split())
c, d = map(int, input().split())
while b != d:
if min(b, d) > 20000:
break
if b > d:
d += c
else:
b += a
print(b if b == d else -1)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-6;
const double Pi = acos(-1);
bool cmp(const pair<int, int> &fi, const pair<int, int> &se) {
return fi.second < se.second;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { ret... | 7 | CPP |
a, b = (int(v) for v in input().split())
c, d = (int(v) for v in input().split())
r = {b+a*i for i in range(100)}
s = {d+c*i for i in range(100)}
i = r.intersection(s)
print(min(i) if len(i) else -1)
| 7 | PYTHON3 |
a, b = map(int, list(input().split()))
c, d = map(int, list(input().split()))
for i in range(0, 1000):
for j in range(0, 1000):
if a * i + b == c * j + d:
print(a * i + b)
exit(0)
print(-1)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long Inf = 1e18;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long a, b, c, d;
cin >> a >> b >> c >> d;
for (int i = max(b, d); i <= 1e6; i++) {
if ((i - b) % a == 0 && (i - d) % c == 0) {
cout << i << '\n';
return 0;
... | 7 | CPP |
def solve(a, b, c, d):
for i in range(0, 101):
j = (b + a * i - d) // c
if 0 <= j and b + a * i == d + c * j:
return b + a * i
return -1
a, b = map(int, input().split())
c, d = map(int, input().split())
print(solve(a, b, c, d))
| 7 | PYTHON3 |
#include <bits/stdc++.h>
int main() {
int a, b, c, d;
int i;
double j;
scanf("%d %d %d %d", &a, &b, &c, &d);
for (i = 0; i <= 100; ++i) {
j = (b + a * i - d) * 1.0 / c;
if (j >= 0 && j == (int)j) {
printf("%d\n", b + a * i);
return 0;
}
}
puts("-1");
return 0;
}
| 7 | CPP |
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from itertools import (
accumulate, combinations, combinations_with_replacement, groupby,
permutations, product)
from math im... | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
bool sortv(const vector<int>& v1, const vector<int>& v2) {
return v1[0] < v2[0];
}
int main() {
ios_base::sync_with_stdio(false);
long long int a, b, x, y;
cin >> a >> b >> x >> y;
for (int i = 0; i <= 500; i++) {
for (int j = 0; j <= 500; j++) {
if (b +... | 7 | CPP |
""" *** Author--Saket Saumya ***
IIITM
"""
import math
import os
import random
import re
from sys import stdin,stdout
from collections import Counter
def si():
return str(input())
def ii():
return int(input())
def mi():
return map(int, input().split())
def li():
return list(mi())
a,b=mi()
c... | 7 | PYTHON3 |
#Winners never quit, quiters never win............................................................................
from collections import deque as de
import math
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping
def factors(n):
return set(reduce(list.__add__... | 7 | PYTHON3 |
from sys import stdin, stdout
a, b = map(int, stdin.readline().rstrip().split())
c, d = map(int, stdin.readline().rstrip().split())
match=-1
set1=set()
for i in range(a+b+max([b,d])):
set1.add(b+i*a)
for i in range(a+b+max([b,d])):
if d+i*c in set1:
match=d+i*c
break
print(match)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int a, b, c, d, i = 1, j = 1;
cin >> a >> b >> c >> d;
long long int ans1 = b;
long long int ans2 = d;
while (1) {
if (ans1 > 10000 || ans2 > 10000) {
cout << "-1";
break;
}
if (ans1 == ans2) {
cout << ans1;
... | 7 | CPP |
a,b=map(int,input().split())
c,d=map(int,input().split())
flag=0
if(b==d):
print(b)
else:
for i in range(100):
for j in range(100):
if b+(i*a)==d+(j*c):
#print(b+(i*a))
flag=1
break
if(flag==1):
break
#else:
... | 7 | PYTHON3 |
a, b = map(int, input().split())
c, d = map(int, input().split())
for i in range(max(max(a, b), max(c, d)) + 1):
if a * i + b - d >= 0 and (a * i + b - d) % c == 0:
print(a * i + b)
exit()
print(-1) | 7 | PYTHON3 |
a, b = map(int, input().split())
c ,d = map(int, input().split())
e=set(range(b,10000,a))
f=set(range(d,10000,c))
g=e & f
print(min(g) if g else -1) | 7 | PYTHON3 |
def scream_times(a,b,c,d):
n = 1000
for i in range(n):
for j in range(n):
if(b+i*a == d+c*j):
return b+i*a
return -1
if __name__ == '__main__':
a,b = map(int,input().split())
c,d = map(int, input().split())
print(scream_times(a,b,c,d)) | 7 | PYTHON3 |
a,b = map(int,input().split())
c,d = map(int,input().split())
valid = [0]*(1000001)
cnt = b
while cnt <= 1000000:
valid[cnt] += 1
cnt += a
cnt = d
while cnt <= 1000000:
valid[cnt] += 1
cnt += c
for i in range(1000001):
if valid[i] == 2:
print(i)
break
else:
print(-1)
... | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
int ans = inf;
for (int i = 0; i <= 1000; i++)
for (int j = 0; j <= 1000; j++) {
if (i * a + b == j * c + d) ans = min(ans, i * a + b);
}
if (ans == inf) ans = -1;
cout << a... | 7 | CPP |
from fractions import gcd
import time
a, b = map(int, input().split())
c, d = map(int, input().split())
gap = abs(b-d)
if gap % (gcd(a, c)) != 0:
print(-1)
exit()
while True:
if b < d:
r = (d - b) % a
if r == 0:
print(d)
exit(0)
b = d + (a - r)
else:
... | 7 | PYTHON3 |
a, b = map(int, input().split())
c, d = map(int, input().split())
if b == d:
print(b)
else:
s = set()
for i in range(0, 101):
s.add(b + a * i)
for i in range(0, 101):
temp = d + c * i
if temp in s:
print(temp)
exit(0)
print(-1)
| 7 | PYTHON3 |
import sys
def diff(a, b):
return abs(a - b)
line1 = input()
line2 = input()
#line1 = '3 5'
#line2 = '3 6'
#line1 = '20 2'
#line2 = '9 19'
#
#line1 = '2 1'
#line2 = '16 12'
interval1 = int(line1.split()[0])
offset1 = int(line1.split()[1])
interval2 = int(line2.split()[0])
offset2 = int(line2.split()[1])
dif... | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
map<long long int, bool> mp1, mp2;
int main() {
long long int n, i, b, a, c, d, sum1 = 0, sum2 = 0;
cin >> a >> b;
cin >> c >> d;
sum1 = b, sum2 = d;
mp1[b] = true;
mp2[d] = true;
for (;;) {
if (sum1 > 10e5) {
break;
}
sum1 += a;
mp1[sum1... | 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]
num_list = []
if b == d:
print(b)
elif a > c:
for i in range(max(c, d // a + 1)):
num_list.append(a * i + b)
for i in num_list:
if (i - d) % c == 0 and i - d >= 0:
p... | 7 | PYTHON3 |
# b + x * a = d + y * c
# x * a - y * c = d - b
def main():
a, b = map(int, input().split())
c, d = map(int, input().split())
s1 = set([b + t * a for t in range(200)])
s2 = set([d + t * c for t in range(200)])
ans = float('inf')
for x in s1:
if x in s2:
ans = min(ans, x)
... | 7 | PYTHON3 |
# Description of the problem can be found at http://codeforces.com/contest/787/problem/0
a, b = map(int, input().split())
c, d = map(int, input().split())
lcm = a * c
for i in range(10000):
t1 = b + i * a
x2 = (t1 - d) // c
if t1 == d + x2*c and x2 >= 0:
print(t1)
quit()
print("-1") | 7 | PYTHON3 |
a, b = map(int, input().split())
c, d = map(int, input().split())
res = -1
k = 0
while (k < a or (d + (k - 1) * c - b) // a < 0) and res == -1:
if (d + k * c - b) % a == 0 and (d + k * c - b) // a >= 0:
res = d + k * c
k += 1
print(res) | 7 | PYTHON3 |
#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 < 100; i++) {
if (d % a == 0) {
cout << d + mn;
return 0;
}
d += c;
}
} else if (d < b... | 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]
num_list = []
if b == d:
print(b)
elif a >= c:
for i in range(max(c, d // a + 1)):
num_list.append(a * i + b)
for i in num_list:
if (i - d) % c == 0 and i - d >= 0:
... | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, c, d;
cin >> a >> b >> c >> d;
for (long long i = 0; i <= 1000000; i++) {
long long pos = b + i * a;
if (pos >= d && ((pos - d) % c == 0)) {
cout << pos << endl;
return 0;
}
}
cout << -1 << endl;
}
| 7 | CPP |
import sys
import collections
from collections import Counter
import itertools
import math
import timeit
#input = sys.stdin.readline
#########################
# imgur.com/Pkt7iIf.png #
#########################
def sieve(n):
if n < 2: return list()
prime = [True for _ in range(n + 1)]
p = 3
while p *... | 7 | PYTHON3 |
a,b=map(int,input().split())
c,d=map(int,input().split())
for i in range(10**5+1):
x=b+(a*i)
if x>=d and (x-d)%c==0:print(x);exit()
print(-1)
| 7 | PYTHON3 |
def gcdex(a, b):
i, j, k, l = 1, 0, 0, 1
while b > 0:
a, b, i, j, k, l = b, a % b, k, l, i - (a // b) * k, j - (a // b) * l
return a, i, j
a1, b1 = map(int, input().split())
c1, d1 = map(int, input().split())
a = a1
b = -c1
c = d1 - b1
d, x, y = gcdex(abs(a), abs(b))
#print(d, x, y)
if c % d... | 7 | PYTHON3 |
import sys
input = sys.stdin.readline
a, b = map(int, input().strip().split())
c, d = map(int, input().strip().split())
# line1 => y = ax + b
# line2 => y = cx + d
arr1 = [b + a*i for i in range(100)]
arr2 = set([d + c*i for i in range(100)])
for ele in arr1:
if ele in arr2:
exit(print(ele))
print(-1)
| 7 | PYTHON3 |
def sol():
for i in range(100):
for j in range(100):
if a*i + b == c*j + d:
print(a*i + b)
return
print(-1)
return
a, b = map(int, input().split())
c, d = map(int, input().split())
sol()
| 7 | PYTHON3 |
a,b = map(int, input().split())
c,d = map(int, input().split())
flag = False
for i in range(500):
for j in range(500):
if b + a*i == d + c*j:
flag = True
print(b+a*i)
if flag: break #break vòng này nếu đã True
if flag: break #break vòng này nếu False
if not flag:
pr... | 7 | PYTHON3 |
def gcd(a, b):
if b == 0: return a
return gcd(b, a % b)
a, b = [int(i) for i in input().split()]
c, d = [int(i) for i in input().split()]
g = gcd(a, c)
if g != 1 and (d - b) % gcd(a, c) != 0:
print (-1)
exit()
s1 = b
s2 = d
if s1 == s2:
print(s1)
exit()
while True:
while s2 < s1:
s2 += c
if s2 == s1:
... | 7 | PYTHON3 |
a, b = list(map(int, input().split()))
c, d = list(map(int, input().split()))
yes = True
for i in range(1, 100):
if a % i == c % i and c % i == 0:
if d % i != b % i:
yes = False
if not yes:
print(-1)
else:
s = set()
for i in range(1000):
s.add(b)
b += a
for i in r... | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int s[N];
bool mp[N];
int main() {
ios::sync_with_stdio(0);
int a, b, c, d;
while (cin >> a >> b >> c >> d) {
memset(mp, 0, sizeof(mp));
int f = -1;
for (int i = 0; i < (2000); i++) {
mp[b] = 1;
b += a;
}
for (int ... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
const long long INF = 1e9 + 5;
vector<long long> v;
map<long long, long long> mp;
void solve() {
long long a, b, c, d;
cin >> a >> b >> c >> d;
long long cnt = 0;
long long tmpb = b, tmpd = d;
for (long long i = 0; i <= 1e5 + 5; i++) {... | 7 | CPP |
a,b=map(int,input().split())
c,d=map(int,input().split())
if b==d:
print(b)
else:
if b<d:
b+=((d-b)//a)*a
for i in range(200):
if (b+i*a-d)%c==0:
print(b+i*a)
break
else:
print(-1)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
int MOD1 = 1000000007;
int MOD2 = 1000000009;
inline bool checkBit(long long int n, long long int i) {
return n & (1LL << i);
}
inline long long int setBit(long long int n, long long int i) {... | 7 | CPP |
from math import floor
a, b = map(int, input().split())
c, d = map(int, input().split())
found = False
for i in range(105):
B = b + i * a
j = (B - d) / c
if j >= 0 and floor(j) == j:
print(b + i * a)
found = True
break
if not found:
print(-1)
| 7 | PYTHON3 |
def main():
a, b = [int(x) for x in input().split()]
c, d = [int(x) for x in input().split()]
rick = b
morty = a
for i in range(100):
for j in range(100):
if (b+i*a)==(d+j*c):
print(b+i*a)
return
print(-1)
return
main()
| 7 | PYTHON3 |
rick = [bool(0)] * 100001
morty = [bool(0)] * 100001
a, b = input().split(' ')
a = int(a)
b = int(b)
c, d = input().split(' ')
c = int(c)
d = int(d)
i = int(1)
krick = -1
rick_krick = b
morty_krick = d
while rick_krick <= 10000:
rick[rick_krick] = 1
rick_krick += a
while morty_krick <= 10000:
morty[morty_kr... | 7 | PYTHON3 |
def input_ints():
return list(map(int, input().split()))
def main():
a, b = input_ints()
c, d = input_ints()
for t in range(10 ** 6):
if t >= b and t >= d and (t - b) % a == 0 and (t - d) % c == 0:
print(t)
return
print(-1)
if __name__ == '__main__':
main()
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e7;
int a, b, c, d;
int main() {
cin >> a >> b >> c >> d;
for (int i = 0; i <= inf; i++) {
if (d - b + c * i >= 0 && (d - b + c * i) % a == 0) {
cout << d + i * c;
return 0;
}
}
cout << -1;
return 0;
}
| 7 | CPP |
a, b = map(int, input().split())
c, d = map(int, input().split())
s1 = set()
s2 = set()
f = False
b -= a
d -= c
for i in range(10 ** 4):
b += a
s1.add(b)
d += c
s2.add(d)
if (b in s2):
print(b)
f = True
break
if (d in s1):
print(d)
f = True
... | 7 | PYTHON3 |
a, b = map(int, input().split())
c, d = map(int, input().split())
ans = None
for i in range(b, 100**2, a):
if i in range(d, 100**2, c):
ans = i
break
if ans == None:
ans = -1
print(ans) | 7 | PYTHON3 |
a, b = map(int, input().split())
c, d = map(int, input().split())
rik = [b + x*a for x in range(500)]
mor = [d + x*c for x in range(500)]
for r in rik:
if r in mor:
print(r)
break
else:
print(-1)
| 7 | PYTHON3 |
r = lambda: map(int,input().split())
a,b = r()
c,d = r()
# a + 2*b
common = set(range(b,100**2,a)) & set(range(d,100**2,c))
print (min(common) if common else -1) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, i, j;
cin >> a >> b >> c >> d;
int f = 0;
for (i = 0; i <= 100; i++) {
for (j = 0; j <= 100; j++) {
if (a * i + b == c * j + d) {
f = 1;
cout << a * i + b << endl;
break;
}
}
if (f == 1) br... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d;
int main() {
while (~scanf("%d%d%d%d", &a, &b, &c, &d)) {
int ans = -1;
for (int i = 0; i < 10000; i++) {
int x = d - b;
int y = a * i - x;
if (y >= 0 && y % c == 0) {
ans = a * i + b;
break;
}
}
prin... | 7 | CPP |
a=list(map(int, input().split()))
b=list(map(int, input().split()))
p=0
for i in range(1000):
for j in range(1000):
if a[1]+i*a[0]==b[1]+j*b[0]:
count=a[1]+i*a[0]
p=1
break
if p==1:
break
if p==1:
print(count)
else:
print(-1) | 7 | PYTHON3 |
a, b = map(int,input().split())
c, d = map(int,input().split())
x = d - b
m = -1
n = 0
if x%a == 0:
while True:
m = m + 1
n = (x+m*c)/a
if n < 0:
continue
if (x+m*c)%a == 0:
print (d+m*c)
break
elif x%a != 0 and c%a == 0:
print(-1)
else:
... | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 7;
const int INF = 1e9 + 7;
int n;
int main() {
int a, b, c, d;
scanf("%d%d%d%d", &a, &b, &c, &d);
int flag = INF;
for (int i = 0; i <= 1000; i++) {
for (int j = 0; j <= 1000; j++)
if (b + i * a == d + j * c) {
flag = min(fla... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d;
int ans;
int main() {
scanf("%d%d%d%d", &a, &b, &c, &d);
ans = -1;
for (int i = 0; i <= 999; ++i)
for (int j = 0; j <= 999; ++j)
if (b + a * i == d + c * j)
ans = min(ans == -1 ? 1000000000 : ans, b + a * i);
printf("%d\n", ans);
... | 7 | CPP |
#include <bits/stdc++.h>
int main() {
int a, b, c, d, x, i, z[105];
scanf("%d%d%d%d", &a, &b, &c, &d);
for (i = 0; i < 105; i++) z[i] = 0;
for (x = 0, i = 0; b != d; i++) {
if (a * i + b - d >= 0) {
if ((a * i + b - d) % c == 0)
break;
else if (z[(a * i + b - d) % c] == 1) {
x = ... | 7 | CPP |
a,b=map(int,input().split())
c,d=map(int,input().split())
for i in range(100000):
if (b+i*a-d)%c==0 and b+i*a-d>=0:
print(b+i*a)
break
else:
print(-1)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, i, j, flag;
while (~scanf("%d%d%d%d", &a, &b, &c, &d)) {
flag = 0;
for (i = 0; i <= 10000; i++) {
for (j = 0; j <= 10000; j++) {
if ((b + a * i) == (d + c * j)) {
flag = 1;
break;
}
i... | 7 | CPP |
def sum_(a_, d_):
return a_ + n * d_
a, b = map(int, input().split(' '))
c, d = map(int, input().split(' '))
lim = a * c + b + d
n = 0
sli = [sum_(b, a)]
while sli[n] <= lim:
n += 1
sli.append(sum_(b, a))
n = 0
slj = [sum_(d, c)]
while slj[n] <= lim:
n += 1
slj.append(sum_(d, c))
r = -1
for i i... | 7 | PYTHON3 |
import sys
[a, b] = [int(x) for x in input().split(" ")]
[c, d] = [int(x) for x in input().split(" ")]
# aX + b == cY + d
maximum = max(a, b, c, d)
for i in range(maximum + 1):
y = (a * i + b - d) / c
x = (c * y + d - b) / a
answer = (a * i + b)
if (x).is_integer() and (y).is_integer() and answer >= m... | 7 | PYTHON3 |
import sys
a, b = map(int, input().split())
c, d = map(int, input().split())
for i in range(max(b,d),100000):
if (i-b) % a == 0 and (i-d) % c == 0:
print(i)
sys.exit()
print(-1)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int b, a, d, c;
cin >> a >> b >> c >> d;
int k = 0;
while (b != d) {
if (d > b) {
b += a;
} else {
d += c;
}
k++;
if (k == 100005) {
cout << "-1";
return 0;
}
}
cout << b;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int a, b, c, d;
cin >> a >> b >> c >> d;
for (int i = max(b, d); i <= 1e5; ++i)
if ((i - b) % a == 0 && (i - d) % c == 0) return cout << i, 0;
cout << -1;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
while (a != b)
if (a > b)
a -= b;
else
b -= a;
return a;
}
int main() {
int a, b, c, d, i = 1, j = 1, k;
cin >> a >> b >> c >> d;
if (abs(d - b) % gcd(a, c))
cout << -1;
else {
while (b != d) {
if (b < d)... | 7 | CPP |
a,b=map(int,input().split())
c,d=map(int,input().split())
t=[]
for n1 in range(1,101):
for n2 in range(1,101):
if(b+(n1-1)*a==d+(n2-1)*c):
t.append(b+(n1-1)*a)
if len(t)!=0:
print(min(t))
else:
print(-1) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, i, j = -1, x, y;
cin >> a >> b >> c >> d;
int t[100], s[100];
for (i = 0; i < 100; i++) {
j++;
x = b + a * i;
t[i] = {x};
y = d + c * j;
s[i] = {y};
}
for (i = 0; i < 100; i++) {
for (j = 0; j < 100; j++) {
... | 7 | CPP |
ans=[]
a,b=map(int,input().split())
c,d=map(int,input().split())
l=[b,b+a]
ll=[d,d+c]
for i in range(100):
l+=[b+i*a]
for i in range(100):
ll+=[d+i*c]
for i in l:
if i in ll: ans+=[i]
if len(ans)==0:
print(-1)
else: print(ans[0])
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int p[100010], q[100010];
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
map<int, int> mp;
for (int i = 0; i <= 10000; i++) {
p[i] = b + a * i;
q[i] = d + c * i;
mp[q[i]] = 1;
}
for (int i = 0; i <= 10000; i++) {
if (mp[p[i]]) {
cout... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int a, b, c, d;
cin >> a >> b >> c >> d;
int flag = 1;
for (int i = 0; i < 100; i++) {
int lhs = a * i + b;
int j = (lhs - d) / c;
if (j < 0) continue;
int rhs = c * j + d;
if (lhs == rhs) {
... | 7 | CPP |
a,b = map(int, input().split())
c,d = map(int, input().split())
for i in range(1000 * 1000):
if (d - b + i * c) % a == 0 and (d - b + i * c) > -1:
print(d + i * c)
exit(0)
print(-1)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
const int maxn = 1000000 + 5;
bool vis[maxn];
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
vis[b] = true;
for (int i = 1; b <= maxn - 5; i++) {
vis[b] = true;
b += a;
}
bool flag = false;
f... | 7 | CPP |
a,b=map(int,input().split())
s=0
c,d=map(int,input().split())
flag=0
while(d!=b):
if(s==100000):
print(-1)
b=d
flag=1
if(d<b):
d+=max(c*((b-d)//c),c)
else:
b+=max(a*((d-b)//a),a)
s+=1
if(flag==0):
print(b)
| 7 | PYTHON3 |
import math
def gcdex(a, b):
if b == 0:
return a, 1, 0
else:
d, x1, y1 = gcdex(b, a % b)
return d, y1, x1 - (a // b) * y1
n1, n2 = map(int, input().split())
n3, n4 = map(int, input().split())
a = n1
b = -n3
c = n4 - n2
d, x0, y0 = gcdex(abs(a), abs(b))
if c % d != 0:
print(-1)
e... | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
bool x[10001000];
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
for (int i = 0; i < 100000; i++) {
x[b + i * a] = 1;
}
bool ok = false;
for (int i = 0; i < 100000; i++) {
int t = d + i * c;
if (x[t]) {
ok = true;
cout << t << endl... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
short a, b, c, d;
cin >> a >> b >> c >> d;
short n1 = b, n2 = d;
do {
if (n2 > n1) do {
n1 += a;
if (n1 < 0) n1 = -1;
} while (n1 > 0 && n2 > n1);
if (n1 > n2) do {
n2 += c;
if (n2 < 0) n1 = -1;
} whil... | 7 | CPP |
def gcd(a, b):
if b == 0:
return a
return gcd(b, a%b)
from sys import stdin
a, b = map(int, stdin.readline().split())
c, d = map(int, stdin.readline().split())
const = b - d + c - a
# m*c + n*(-a) = const
# Linear Diophantine equation gives the below if condition.
if const%gcd(a, c) == 0:
for m i... | 7 | PYTHON3 |
l=input().split()
s=input().split()
a=int(l[0])
b=int(l[1])
c=int(s[0])
d=int(s[1])
t=[]
p=[]
f=1
i=0
while(i<1000):
t.append(b+i*a)
p.append(d+i*c)
if(b+i*a in p):
print(b+i*a)
f=0
break
if(d+i*c in t):
print(d+i*c)
f=0
break
i+=1
if(f):
print("-1") | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int main() {
ios::sync_with_stdio(0);
int a, b, c, d;
scanf("%d %d", &a, &b);
scanf("%d %d", &c, &d);
for (int i = 0; i < 10000000; i++) {
int k = b + a * i;
if (k - d < 0) continue;
if ((k - d) % c == 0) {
printf("%d"... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
int i;
double j;
cin >> a >> b >> c >> d;
for (i = 0; i <= 100; ++i) {
j = (b + a * i - d) * 1.0 / c;
if (j >= 0 && j == (int)j) {
cout << (b + a * i);
return 0;
}
}
cout << -1 << endl;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int INF = 1000001000;
const long long INFLL = INF * 1LL * INF;
const int mod = 1000 * 1000 * 1000 + 7;
const int mod9 = 1000 * 1000 * 1000 + 9;
const int modr = 99990001;
const long double PI = 3.1415926535897932385;
templat... | 7 | CPP |
#The Monster
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 > ... | 7 | PYTHON3 |
def gcd(a,b):
if a < 0:
a = -a
if b < 0:
b = -b
while b != 0:
r = a % b
a,b = b, r
return a
a,b = map(int, input().split())
c, d = map(int, input().split())
if (d - b) % gcd(a, c) != 0:
print(-1)
else:
i = 0
while True:
j = (b + i*a-d)//c
if j >= 0 and (b + i*a == d+j*c):
print(b + i*a)
break
... | 7 | PYTHON3 |
def main():
a, b = map(int, input().split())
c, d = map(int, input().split())
for i in range(100000):
if i - b >= 0 and (i - b) % a == 0:
if i - d >= 0 and (i - d) % c == 0:
print(i)
return
print(-1)
main() | 7 | PYTHON3 |
a,b = map(int,input().split())
c,d = map(int,input().split())
for i in range(0,1000):
for j in range(0,1000):
if b + a*i == d + c*j:
print(b + a*i)
exit(0)
print(-1)
| 7 | PYTHON3 |
import sys
a, b = map(int, input().split())
c, d = map(int, input().split())
s = set()
for i in range(1001):
s.add( b + i * a)
for i in range(1000):
num = d + c * i
if num in s:
print(num)
sys.exit()
print(-1)
| 7 | PYTHON3 |
inp = input().split()
a = int(inp[0])
b = int(inp[1])
inp = input().split()
c = int(inp[0])
d = int(inp[1])
for x in range(101):
for y in range(101):
if (a*x+b) == (c*y+d):
print(a*x+b)
exit(0)
print(-1) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int a, b, c, d;
while (cin >> a >> b >> c >> d) {
map<long long int, long long int> p;
for (long long int i = 0; i <= 100; i++) {
long long int x = b + a * i;
p[x] = 1;
}
bool f = true;
for (long long int i = 0; i <... | 7 | CPP |
a,b = map(int,input().split())
c,d = map(int,input().split())
for i in range(100000):
if(b+a*i-d)>=0 and (b+a*i-d)%c==0:
print(b+a*i)
break
else:
print(-1) | 7 | PYTHON3 |
i=1
yes=-1
y=0
a,b=map(int,input().split())
c,d=map(int,input().split())
#both Equations are in a form of straight line.
#the case is if we draw one line segment prependicular on y then
#definetly, the two points will pass through that line and Morty and Rick must be equal.
#i*a+b=j*c+d,
if(b==d):
print(d)
else:
... | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
int i = 0, j = 0;
while (b != d && i <= 100 && j <= 100) {
if (b > d) {
d += c;
j++;
} else {
b += a;
i++;
}
}
if (i <= 100 && j <= 100)
cout << d << endl;
else
c... | 7 | CPP |
a,b = map(int,input().split(' '))
c,d = map(int,input().split(' '))
for x in range(0,101):
f = False
for y in range(0,101):
if (a*x+b) - (c*y+d) == 0:
print(a*x+b)
f = True
break
if f:
break;
if f == False:
print(-1)
| 7 | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.