結果

問題 No.751 Frac #2
ユーザー fura
提出日時 2020-05-05 14:41:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 447 bytes
コンパイル時間 2,260 ms
コンパイル使用メモリ 191,684 KB
最終ジャッジ日時 2025-01-10 06:47:19
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |         int n; scanf("%d",&n);
      |                ~~~~~^~~~~~~~~
main.cpp:12:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |                 int a; scanf("%d",&a);
      |                        ~~~~~^~~~~~~~~
main.cpp:16:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |         int m; scanf("%d",&m);
      |                ~~~~~^~~~~~~~~
main.cpp:18:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |                 int b; scanf("%d",&b);
      |                        ~~~~~^~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int main(){
	int n; scanf("%d",&n);
	lint nu=1,de=1;
	rep(i,n){
		int a; scanf("%d",&a);
		if(i==0) nu*=a;
		else     de*=a;
	}
	int m; scanf("%d",&m);
	rep(i,m){
		int b; scanf("%d",&b);
		if(i%2==0) de*=b;
		else       nu*=b;
	}
	lint g=gcd(nu,de);
	nu/=g;
	de/=g;
	if(de<0) nu*=-1, de*=-1;
	printf("%lld %lld\n",nu,de);
	return 0;
}
0