結果

問題 No.443 GCD of Permutation
ユーザー square1001square1001
提出日時 2018-05-19 20:25:38
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 828 bytes
コンパイル時間 696 ms
コンパイル使用メモリ 86,024 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-28 14:29:01
合計ジャッジ時間 2,109 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 24 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <random>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int p[] = { 2, 3, 5, 7 };
string s;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> s;
	bool same = true;
	for (int i = 1; i < s.size(); i++) {
		if (i >= 1 && s[i] != s[i - 1]) same = false;
	}
	if (same) cout << s << '\n';
	else {
		int ret = 1;
		for (int i = 0; i < 4; i++) {
			int z = 1 << 30;
			for (int j = 0; j < 20; j++) {
				random_shuffle(s.begin(), s.end());
				int mod = p[i] * p[i] * p[i] * p[i] * p[i] * p[i], cur = 0;
				for (int k = 0; k < s.size(); k++) {
					cur = (cur * 10 + (s[k] - '0')) % mod;
				}
				int c = 0;
				while (c < 6 && cur % p[i] == 0) cur /= p[i], c++;
				z = min(z, c);
			}
			for (int j = 0; j < z; j++) ret *= p[i];
		}
		cout << ret << '\n';
	}
	return 0;
}
0