結果

問題 No.442 和と積
ユーザー mamekinmamekin
提出日時 2016-11-12 13:07:14
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,508 bytes
コンパイル時間 1,036 ms
コンパイル使用メモリ 112,460 KB
実行使用メモリ 8,768 KB
最終ジャッジ日時 2023-08-24 18:23:19
合計ジャッジ時間 4,020 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
7,484 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 12 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

void integerFactorization(long long n, vector<long long>& base, vector<int>& expo)
{
    base.clear();
    expo.clear();
    long long a = 2;
    while(a * a <= n){
        int b = 0;
        while(n % a == 0){
            ++ b;
            n /= a;
        }
        if(b > 0){
            base.push_back(a);
            expo.push_back(b);
        }
        ++ a;
    }
    if(n > 1){
        base.push_back(n);
        expo.push_back(1);
    }
}

int main()
{
    long long a, b;
    cin >> a >> b;

    vector<long long> base;
    vector<int> expo;
    map<long long, int> m;

    integerFactorization(a, base, expo);
    for(unsigned i=0; i<base.size(); ++i)
        m[base[i]] += expo[i];
    integerFactorization(b, base, expo);
    for(unsigned i=0; i<base.size(); ++i)
        m[base[i]] += expo[i];

    integerFactorization(a+b, base, expo);
    long long ans = 1;
    for(unsigned i=0; i<base.size(); ++i){
        int x = min(expo[i], m[base[i]]);
        while(--x >= 0)
            ans *= base[i];
    }
    cout << ans << endl;

    return 0;
}
0