結果
| 問題 |
No.186 中華風 (Easy)
|
| コンテスト | |
| ユーザー |
h_noson
|
| 提出日時 | 2016-03-17 12:06:39 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 22 ms / 2,000 ms |
| コード長 | 940 bytes |
| コンパイル時間 | 464 ms |
| コンパイル使用メモリ | 59,584 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-19 18:27:26 |
| 合計ジャッジ時間 | 1,455 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,n,0)
#define REP(i,s,e) for (i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1e8
typedef long long ll;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b,a%b);
}
ll lcm(ll a, ll b) {
return a*b/gcd(a,b);
}
int main() {
ll i;
ll x[3], y[3];
rep (i,3) cin >> x[i] >> y[i];
rep (i,1000001) {
ll n = y[0]*i+x[0];
if (n != 0 && n%y[1]==x[1]) {
y[1] = lcm(y[0],y[1]);
x[1] = n;
break;
}
}
if (i == 1000001) {
cout << -1 << endl;
return 0;
}
rep (i,1000001) {
ll n = y[1]*i+x[1];
if (n != 0 && n%y[2]==x[2]) {
cout << n << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
}
h_noson