結果

問題 No.751 Frac #2
ユーザー U-ArU-Ar
提出日時 2018-11-23 14:51:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,312 bytes
コンパイル時間 388 ms
コンパイル使用メモリ 53,100 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-26 04:11:51
合計ジャッジ時間 1,608 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,384 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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