結果

問題 No.1931 Fraction 2
ユーザー 👑 kmjpkmjp
提出日時 2022-05-28 01:09:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 551 ms / 2,000 ms
コード長 1,798 bytes
コンパイル時間 2,424 ms
コンパイル使用メモリ 213,968 KB
実行使用メモリ 48,980 KB
最終ジャッジ日時 2023-10-20 22:08:19
合計ジャッジ時間 15,781 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
20,692 KB
testcase_01 AC 9 ms
20,696 KB
testcase_02 AC 8 ms
20,692 KB
testcase_03 AC 10 ms
20,804 KB
testcase_04 AC 10 ms
20,812 KB
testcase_05 AC 10 ms
20,788 KB
testcase_06 AC 10 ms
20,832 KB
testcase_07 AC 10 ms
20,792 KB
testcase_08 AC 9 ms
20,740 KB
testcase_09 AC 10 ms
20,804 KB
testcase_10 AC 9 ms
20,704 KB
testcase_11 AC 10 ms
20,792 KB
testcase_12 AC 9 ms
20,736 KB
testcase_13 AC 103 ms
26,068 KB
testcase_14 AC 363 ms
38,800 KB
testcase_15 AC 162 ms
28,952 KB
testcase_16 AC 31 ms
22,172 KB
testcase_17 AC 45 ms
22,812 KB
testcase_18 AC 489 ms
45,604 KB
testcase_19 AC 496 ms
45,592 KB
testcase_20 AC 492 ms
45,596 KB
testcase_21 AC 491 ms
45,672 KB
testcase_22 AC 490 ms
45,676 KB
testcase_23 AC 493 ms
45,668 KB
testcase_24 AC 488 ms
45,584 KB
testcase_25 AC 498 ms
45,640 KB
testcase_26 AC 493 ms
45,580 KB
testcase_27 AC 489 ms
45,616 KB
testcase_28 AC 551 ms
48,964 KB
testcase_29 AC 550 ms
48,968 KB
testcase_30 AC 550 ms
48,960 KB
testcase_31 AC 546 ms
48,980 KB
testcase_32 AC 550 ms
48,972 KB
testcase_33 AC 547 ms
48,948 KB
testcase_34 AC 547 ms
48,972 KB
testcase_35 AC 545 ms
48,980 KB
testcase_36 AC 547 ms
48,972 KB
testcase_37 AC 545 ms
48,980 KB
testcase_38 AC 9 ms
20,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N;
const ll mo=998244353;
ll A[202020],B[202020];
ll C,D;
vector<int> cand[202020];
map<int,int> di[202020];
ll modpow(ll a, ll n = mo-2, ll mo_=mo) {
	ll r=1;a%=mo_;
	while(n) r=r*((n%2)?a:1)%mo_,a=a*a%mo_,n>>=1;
	return r;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>A[i]>>B[i];
	}
	FOR(i,N) {
		x=B[i];
		for(j=2;j*j<=x;j++) if(x%j==0) {
			cand[j].push_back(i);
			while(x%j==0) x/=j, di[i][j]++;
		}
		if(x>1) cand[x].push_back(i), di[i][x]++;
	}
	ll P=1;
	D=1;
	for(i=2;i<=200000;i++) if(cand[i].size()) {
		int ma=0;
		FORR(c,cand[i]) ma=max(ma,di[c][i]);
		D=D*modpow(i,ma)%mo;
		ll sum=0;
		ll p=modpow(i,ma);
		ll m=p/i*(i-1);
		FORR(c,cand[i]) {
			sum+=A[c]*modpow(i,ma-di[c][i])%p*modpow(B[c]/modpow(i,di[c][i]),m-1,p)%p;
		}
		sum%=p;
		if(sum==0) {
			P=P*p%mo;
		}
		else {
			while(sum%i==0) {
				sum/=i;
				P=P*i%mo;
			}
		}
	}
	FOR(i,N) {
		C+=A[i]*D%mo*modpow(B[i])%mo;
	}
	
	
	cout<<C%mo*modpow(P)%mo<<" "<<D*modpow(P)%mo<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0