結果
問題 | No.186 中華風 (Easy) |
ユーザー |
![]() |
提出日時 | 2020-02-23 14:30:35 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 173 ms / 2,000 ms |
コード長 | 993 bytes |
コンパイル時間 | 1,576 ms |
コンパイル使用メモリ | 168,504 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-19 18:38:21 |
合計ジャッジ時間 | 3,302 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);++i) #define rrep(i,n) for(int i=1;i<(n);++i) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin,(a).rend() #define dunk(a) cout << (a) << endl using namespace std; typedef long long ll; const int inf = 1001001001; const int mod = 1000000007; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } int main() { ios::sync_with_stdio(false); cin.tie(0); vector<ll> x(3), y(3); rep(i, 3) cin >> x[i] >> y[i]; ll ans; ll pin = y[1] + 1; bool elf = false; rep(i, pin) { ll res = x[0] + y[0] * i; if (res % y[1] == x[1]) { elf = true; ans = res; break; } } if (!elf) { puts("-1"); return 0; } elf = false; pin = y[2] + 1; rep(i, pin) { ll res = ans + lcm(y[0], y[1]) * i; if (res % y[2] == x[2]) { elf = true; ans = res; break; } } if (!elf) { puts("-1"); return 0; } dunk(ans != 0 ? ans : lcm(y[0], lcm(y[1], y[2]))); return 0; }