結果

問題 No.186 中華風 (Easy)
ユーザー tubo28tubo28
提出日時 2015-10-23 18:39:40
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,661 bytes
コンパイル時間 565 ms
コンパイル使用メモリ 66,680 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-29 17:44:01
合計ジャッジ時間 1,842 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,376 KB
testcase_11 WA -
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 WA -
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cassert>
#include <tuple>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef __int128_t lll;

#define abs(a) (a > 0 ? a : -a)

lll extgcd(lll a, lll b, lll &x, lll &y) {
  for (lll u = y = 1, v = x = 0; a; ) {
    lll q = b / a;
    swap(x -= q * u, u);
    swap(y -= q * v, v);
    swap(b -= q * a, a);
  }
  return b;
}

lll gcd(lll a, lll b){
  return b ? gcd(b,a%b) : a;
}

lll lcm(lll a, lll b){
  return a/gcd(a,b)*a;
}

lll modinv(lll x, lll m) {
  lll s, t;
  extgcd(x, m, s, t);
  return (m+s) % m;
}

// x, mod
pair<lll,lll> crt(lll a1, lll m1, lll a2, lll m2){
  lll k1,k2;
  lll g = extgcd(m1,m2,k1,k2);
  if(abs(a1-a2)%g != 0){
    return make_pair(-1,-1);
  } else {
    lll l = m1 / g * m2;
    k1 *= (a2-a1)/g;
    k2 *= (a2-a1)/(-g);
    assert((a2-a1)%g == 0);
    assert((a2-a1)%(-g) == 0);
    assert(m1*k1 - m2*k2 == a2-a1);
    // printf("%lld %lld %lld %lld\n", (ll)m1,(ll)k1,(ll)m2,(ll)k2);
    lll x1 = (a1 + k1%l*m1%l) % l;
    lll x2 = (a2 + k2%l*m2%l) % l;
    // printf("x1=%lld x2=%lld\n", (ll)x1,(ll)x2);
    assert(x1 == x2);
    return make_pair(x1,l);
  }
}

int n;
lll x[1010], y[1010];
const lll mod = 1000000007;

pair<lll,lll> solve(){
  lll m = 1, ans = 0;
  for(int i = 0; i < 3; i++){
    tie(ans,m) = crt(ans, m, x[i], y[i]);
    if(ans == -1) return make_pair(-1,-1);
  }
  return make_pair(ans,m);
}

int main(){
  while(1){
    for(int i = 0; i < 3; i++){
      ll xx,yy;
      if(!(cin >> xx >> yy)) exit(0);
      x[i] = xx, y[i] = yy;
    }
    lll ans,m;
    tie(ans,m) = solve();
    if(ans == 0) ans = m;
    cout << (ll)ans << endl;
  }
}
0