結果

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

ソースコード

diff #

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

int __gcd(int a, int b){
	if (a > b){
		swap(a, b);
	}
	while (a){
		swap(a, b);
		a %= b;
	}
	return b;
}

string s;

set<int> S;
int main(){
	cin >> s;
	int sum = 0;
	bool f = true;
	for (int i = 0; i < s.size(); i++){
		S.insert(s[i] - '0');
		sum += (s[i] - '0');
		if ((s[i] - '0') % 2){
			f = false;
		}
	}
	if (S.size() == 1){
		cout << s << endl;
		return 0;
	}
	int gc = 0;
	for (auto it = S.begin(); it != S.end(); it++){
		for (auto itt = S.begin(); itt != S.end(); itt++){
			int sa = abs(10 * (*it) + (*itt) - (10 * (*itt) + (*it)));
			gc = __gcd(gc, sa);
		}
	}
	if (gc % 9 == 0 && sum % 9){
		gc /= 9;
	}
	if (gc % 3 == 0 && sum % 3){
		gc /= 3;
	}
	while (f==false&&gc % 2 == 0){
		gc /= 2;
	}
	cout << gc << endl;
	return 0;
}
0