結果

問題 No.751 Frac #2
ユーザー k
提出日時 2020-07-19 19:35:42
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 847 bytes
コンパイル時間 2,198 ms
コンパイル使用メモリ 194,744 KB
最終ジャッジ日時 2025-01-12 00:55:55
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

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

long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  return gcd(b, a%b);    
}

// override function template of std::gcd
long long gcd(int a, int b) {
  return gcd((long long)a, (long long)b);
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n1;
  cin >> n1;
  vector<long long> a(n1);
  REP (i, n1) cin >> a[i];

  int n2;
  cin >> n2;
  vector<long long> b(n2);
  REP (i, n2) cin >> b[i];

  long long p = a[0], q = 1;

  for (int i = 1; i < n1; i++) q *= a[i];
  for (int i = 0; i < n2; i++) {
    if (i % 2 == 0)
      q *= b[i];
    else
      p *= b[i];
  }

  long long g = gcd(abs(p), abs(q));
  p /= g;
  q /= g;

  p *= q / abs(q);
  q = abs(q);
    
  cout << p << " " << q << endl;
  
  return 0;
}
0