結果

問題 No.443 GCD of Permutation
ユーザー kyuridenamidakyuridenamida
提出日時 2016-11-11 22:38:19
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 807 bytes
コンパイル時間 1,272 ms
コンパイル使用メモリ 149,908 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-16 18:59:44
合計ジャッジ時間 2,479 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef __int128 Int;

int f(string t){
	sort(t.begin(),t.end());
	long long w = -1;
	do{
		long long x = atoi(t.c_str());
		if( w == -1 ) w = x;
		w = __gcd(x,w);
	}while(next_permutation(t.begin(),t.end()));		
	return w;
}
bool single(string s){
	return s.size() == count(s.begin(),s.end(),s[0]);
}
int main(){
	string s;
	cin >> s;
	if( single(s) ){
		cout << s << endl;
		return 0;
	}
	if( s.size() <= 6 ){
		cout << f(s) << endl;
		return 0;
	}
	int sum = 0;
	for(auto &c : s ) sum += c - '0';
	int ev = 1;
	for(int i = 8 ; i >= 2 ; i-=2){
		int f = 1;
		for(int j = 0 ; j < s.size() ; j++)
			if( (s[j] - '0') % i != 0 ){
				f = 0;
			}
		if(f){
			ev = i;
			break;
		}
	}
	int od = sum % 9 == 0 ? 9 : sum % 3 == 0 ? 3 : 1;
	cout << od * ev << endl;

}
0