結果

問題 No.442 和と積
ユーザー square1001square1001
提出日時 2016-11-25 15:47:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 790 bytes
コンパイル時間 1,544 ms
コンパイル使用メモリ 173,676 KB
実行使用メモリ 7,644 KB
最終ジャッジ日時 2023-08-24 18:23:36
合計ジャッジ時間 4,516 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
std::map<unsigned long long, unsigned> prime_factorize(unsigned long long x) {
	std::map<unsigned long long, unsigned> ret;
	for (unsigned i = 2; 1ULL * i * i <= x; i++) {
		while (x % i == 0) x /= i, ret[i]++;
	}
	if (x != 1) ret[x]++;
	return ret;
}
long long A, B;
int main() {
	cin >> A >> B;
	map<unsigned long long, unsigned> r1 = prime_factorize(A + B);
	map<unsigned long long, unsigned> r2 = prime_factorize(A);
	map<unsigned long long, unsigned> r3 = prime_factorize(B);
	for(pair<unsigned long long, unsigned> i : r3) r2[i.first] += i.second;
	long long ret = 1;
	for(pair<unsigned long long, unsigned> i : r2) {
		int x = min(i.second, r1[i.first]);
		for(int j = 0; j < x; j++) ret *= i.first;
	}
	cout << ret << endl;
	return 0;
}
0