結果

問題 No.443 GCD of Permutation
ユーザー kyuridenamida
提出日時 2016-11-11 22:44:07
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 947 bytes
コンパイル時間 1,481 ms
コンパイル使用メモリ 163,568 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-25 09:00:10
合計ジャッジ時間 2,079 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21 WA * 7
権限があれば一括ダウンロードができます

ソースコード

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 fv = 5;
	for( auto c : s ){
		if( c != '0' and c != '5' ) fv = 1;
	}
	int od = 1;
	int th = 1;
	for(int i = 1 ; i <= 15 ; i++){
		th *= 3;
		if( sum % th == 0 ){
			od = th;
		}
	}
	cout << od * ev * fv << endl;

}
0