結果

問題 No.751 Frac #2
ユーザー U-Ar
提出日時 2018-11-23 14:51:08
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,312 bytes
コンパイル時間 488 ms
コンパイル使用メモリ 55,388 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-24 18:08:14
合計ジャッジ時間 1,482 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;

int a[10];
int b[10];

int afact[11];//0番目の要素は符号判定
int bfact[11];

void dcmp(int n, int* list){
    if (n < 0){
        list[0]++;
        n *= -1;
    }
    for (int i = 2; i < 10; i++){
        while (n % i == 0){
            n /= i;
            list[i]++;
        }
    }
}

int main() {
    for (int i = 0; i < 11; i++){
        afact[i] = 0;
        bfact[i] = 0;
    }
    int n1, n2;
    int tmp;

    cin >> n1;
    for (int i = 0; i < n1; i++)
        cin >> a[i];

    
    cin >> n2;
    for (int i = 0; i < n2; i++)
        cin >> b[i];
    
    dcmp(a[0],afact);
    for (int i = 1; i < n1; i++)
        dcmp(a[i],bfact);
    for (int i = 0; i < n2; i++)
        if (i % 2 == 0)
            dcmp(b[i],bfact);
        else 
            dcmp(b[i],afact);
    
    long child = 1;
    long mother = 1;
    if ((afact[0] - bfact[0]) % 2 != 0)
        child *= -1;
    for (int i = 2; i < 11; i++){
        if (afact[i] > bfact[i]){
            for (int j = 0; j < afact[i]-bfact[i]; j++){
                child *= i;
            }
        }
        else if (afact[i] < bfact[i]){
            for (int j = 0; j < bfact[i]-afact[i]; j++){
                mother *= i;
            }
        }
    }
    cout << child << " " << mother << "\n";

}
0