mirror of
https://github.com/tiennm99/codeforces.git
synced 2026-10-14 06:17:38 +00:00
[Init] Solved solutions
This commit is contained in:
1 parent
51f667ac81
commit
20542601dd
131 files changed
+4148
No files matched your search
+43
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
|
||||
namespace _787A
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
int[] b = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
|
||||
if ((a[1] - b[1]) % GCD(a[0], b[0]) == 0)
|
||||
{
|
||||
while (a[1] != b[1])
|
||||
{
|
||||
if (a[1] < b[1])
|
||||
{
|
||||
a[1] += a[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
b[1] += b[0];
|
||||
}
|
||||
}
|
||||
Console.WriteLine(a[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine(-1);
|
||||
}
|
||||
}
|
||||
static int GCD(int a, int b)
|
||||
{
|
||||
int t;
|
||||
while (b != 0)
|
||||
{
|
||||
t = a % b;
|
||||
a = b;
|
||||
b = t;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user