結果
問題 | No.186 中華風 (Easy) |
ユーザー |
![]() |
提出日時 | 2016-03-28 01:40:10 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 24 ms / 2,000 ms |
コード長 | 965 bytes |
コンパイル時間 | 604 ms |
コンパイル使用メモリ | 73,748 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-19 18:27:30 |
合計ジャッジ時間 | 1,470 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <iostream> #include <vector> #include <map> #include <algorithm> #include <limits.h> #include <time.h> #include <string> #include <string.h> #include <sstream> #include <set> #include <cstdio> #include <cstdlib> #include <cmath> #include <stack> #include <queue> using namespace std; typedef long long ll; ll gcd(ll a, ll b){ if(b == 0) return a; return gcd(b, a%b); } ll lcm(ll a, ll b){ return a*b / gcd(a, b); } int main(){ ll x1, y1, x2, y2, x3, y3; cin >> x1 >> y1; cin >> x2 >> y2; cin >> x3 >> y3; ll n1, n2; bool success = false; ll l = lcm(y1, y2); for(int i = 0; i <= y2 && !success; i++){ n1 = x1 + y1 * i; if (n1 > 0 && n1 % y2 == x2) { for(int j = 0; j <= y3 && !success; j++){ n2 = n1 + l * j; if (n2 % y3 == x3) { success = true; break; } } } } if (success) { cout << n2 << endl; } else { cout << -1 << endl; } return 0; }