結果

問題 No.736 約比
ユーザー delt
提出日時 2019-03-04 23:01:14
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 594 bytes
コンパイル時間 514 ms
コンパイル使用メモリ 63,320 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-23 14:02:40
合計ジャッジ時間 2,248 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 65
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

long long gcd(long long a, long long b){
  while(1){
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}

int main(void){
  int n;
  cin >> n;
  long long a[n];
  for(int i = 0; i < n; i++) cin >> a[i];
  long long g = gcd(a[0], a[1]);
  for(int i = 2; i < n; i++) g = gcd(g, a[i]);
  for(int i = 0; i < n; i++) a[i] /= g;
  string ans = "";
  for(int i = 0; i < n; i++){
    ans += to_string(a[i]);
    if(i != n - 1) ans += ":";
  }
  cout << ans << endl;
  return 0;
}
0