結果

問題 No.442 和と積
ユーザー square1001square1001
提出日時 2016-11-25 15:46:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 791 bytes
コンパイル時間 1,757 ms
コンパイル使用メモリ 174,936 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-08-18 07:33:43
合計ジャッジ時間 4,806 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 11 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
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.second]);
		for(int j = 0; j < x; j++) ret *= i.first;
	}
	cout << ret << endl;
	return 0;
}
0