結果

問題 No.186 中華風 (Easy)
ユーザー simansiman
提出日時 2016-03-28 01:38:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 955 bytes
コンパイル時間 605 ms
コンパイル使用メモリ 73,756 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 04:14:52
合計ジャッジ時間 1,912 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
6,812 KB
testcase_01 AC 5 ms
6,940 KB
testcase_02 AC 5 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 12 ms
6,944 KB
testcase_05 AC 10 ms
6,940 KB
testcase_06 AC 15 ms
6,940 KB
testcase_07 AC 13 ms
6,940 KB
testcase_08 AC 18 ms
6,944 KB
testcase_09 AC 18 ms
6,944 KB
testcase_10 AC 19 ms
6,944 KB
testcase_11 AC 23 ms
6,944 KB
testcase_12 AC 7 ms
6,940 KB
testcase_13 AC 8 ms
6,940 KB
testcase_14 AC 9 ms
6,944 KB
testcase_15 AC 3 ms
6,944 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 4 ms
6,940 KB
testcase_19 AC 12 ms
6,940 KB
testcase_20 AC 5 ms
6,940 KB
testcase_21 AC 11 ms
6,940 KB
testcase_22 AC 12 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 % 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;
}
0