結果

問題 No.1931 Fraction 2
ユーザー ytqm3ytqm3
提出日時 2022-04-15 21:03:45
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,781 bytes
コンパイル時間 4,387 ms
コンパイル使用メモリ 267,084 KB
実行使用メモリ 29,176 KB
最終ジャッジ日時 2023-09-20 22:30:35
合計ジャッジ時間 13,772 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
14,780 KB
testcase_01 AC 11 ms
14,856 KB
testcase_02 AC 10 ms
14,640 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 12 ms
14,884 KB
testcase_10 WA -
testcase_11 AC 13 ms
14,756 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using i64=long long;
using u64=unsigned long long;
using namespace std;
template<u64 mod> using modint=atcoder::static_modint<mod>;

struct primefact{
  int n;
  vector<i64> lpf;
  primefact(int n_):n(n_),lpf(n_+1,-1){
    for(i64 p=2;p<=n;++p){
      if(lpf[p]!=-1){
        continue;
      }
      lpf[p]=p;
      for(i64 q=p;q<=n;q+=p){
        if(lpf[q]==-1){
          lpf[q]=p;
        }
      }
    }
  }
  vector<pair<i64,i64>> operator()(int m){
    vector<i64> v;
    while(m!=1){
      v.emplace_back(lpf[m]);
      m/=lpf[m];
    }
    if(v.size()==0){
      return {};
    }
    vector<pair<i64,i64>> res;
    res.emplace_back(v[0],1);
    for(size_t i=1;i<v.size();++i){
      if(v[i-1]!=v[i]){
        res.emplace_back(v[i],1);
      }
      else{
        res.back().second++;
      }
    }
    return res;
  }
};

int main(){
  constexpr u64 mod=998244353;
  typedef modint<mod> mint;
  primefact pf(300'001);
  int N;
  cin>>N;
  vector<i64> A(N),B(N);
  vector<vector<pair<i64,i64>>> idx(300'001);
  vector<i64> m(300'001);
  mint sm=0;
  for(int i=0;i<N;++i){
    cin>>A[i]>>B[i];
    sm+=mint(A[i])/B[i];
    auto tmp=pf(B[i]);
    for(auto [p,e]:tmp){
      idx[p].emplace_back(i,e);
      m[p]=max(m[p],e);
    }
  }
  mint d=1;
  for(i64 p=2;p<=300'001;++p){
    if(m[p]==0){
      continue;
    }
    vector<i64> pw(21,1);
    for(int i=1;i<=20;++i){
      pw[i]=pw[i-1]*p;
    }
    i64 sm=0;
    for(auto [i,e]:idx[p]){
      sm+=A[i]*atcoder::inv_mod(B[i]/pw[e],pw[m[p]]);
      sm%=pw[m[p]];
    }
    i64 prd=pw[m[p]];
    for(int i=0;i<m[p];++i){
      if(sm%p==0){
        sm/=p;
        prd/=p;
      }
      else{
        break;
      }
    }
    d*=prd;
  }
  cout<<(sm*d).val()<<" "<<d.val()<<endl;
}
0