結果

問題 No.2117 中国剰余定理入門
ユーザー keisuke6
提出日時 2022-11-04 21:24:02
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 346 bytes
コンパイル時間 1,921 ms
コンパイル使用メモリ 192,232 KB
最終ジャッジ日時 2025-02-08 17:14:46
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  swap(a,b);swap(c,d);
  while(a < 0) a += b;
  while(c <  0) c += d;
  a %= b;
  c %= d;
  int n = 0;
  while((n%b != a || n%d != c) && n < 1e7)n++;
  if(n > 1e6){
      cout<<"NaN"<<endl;
      return 0;
  }
  cout<<n<<endl;
}
0