結果

問題 No.186 中華風 (Easy)
ユーザー ayanamizutaayanamizuta
提出日時 2019-01-24 14:53:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 804 bytes
コンパイル時間 1,332 ms
コンパイル使用メモリ 145,004 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 00:53:26
合計ジャッジ時間 2,748 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

long long gcd(long long a,long long b){
  if(b==0)return a;
  if(a<b)return gcd(b,a);
  return gcd(b,a%b);
}

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

bool bl=false;

long long solve(long long x1,long long y1,long long x2,long long y2){
  REP(i,y2){
    if((x1+i*y1)%y2==x2)return (x1+i*y1)%lcm(y1,y2);
  }
  bl=true;
  return -1;
}

LL x[3],y[3];

int main(){
  cin>>x[0]>>y[0]>>x[1]>>y[1]>>x[2]>>y[2];
  LL ret,lc=lcm(y[0],y[1]);
  ret = solve(x[0],y[0],x[1],y[1]);
  ret = solve(ret,lc,x[2],y[2]);
  if(bl){
    cout<<-1<<endl;
    return 0;
  }
  cout<<((ret%(lcm(lc,y[2]))==0)?lcm(lc,y[2]):ret%(lcm(lc,y[2])))<<endl;
  return 0;
}
0