結果

問題 No.2119 一般化百五減算
ユーザー umezoumezo
提出日時 2022-11-04 23:10:27
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 841 bytes
コンパイル時間 2,035 ms
コンパイル使用メモリ 201,712 KB
実行使用メモリ 4,700 KB
最終ジャッジ日時 2023-09-26 01:39:59
合計ジャッジ時間 3,355 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

inline ll mod(ll a,ll m){
  return (a%m+m)%m;
}

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int n,m;
  cin>>n>>m;
  vector<int> B(m),C(m);
  rep(i,m){
    cin>>B[i]>>C[i];
    C[i]=mod(C[i],B[i]);
  }
  
  vector<int> A(100100,-1);
  rep(i,m){
    if(A[B[i]]==-1){
      A[B[i]]=C[i];
    }
    else if(A[B[i]]!=C[i]){
      cout<<"NaN"<<endl;
      return 0;
    }
  }
  
  int cnt=0;
  vector<int> ANS(n+1);
  for(int i=1;i<=100000;i++){
    if(A[i]==-1) continue;
    cnt++;
    for(int j=A[i];j<=n;j+=i){
      ANS[j]++;
    }
  }
  for(int i=0;i<=n;i++){
    if(ANS[i]==cnt){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<"NaN"<<endl;

  return 0;
}
0