結果

問題 No.443 GCD of Permutation
ユーザー simezi_tan
提出日時 2016-12-03 15:29:14
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 1,024 bytes
コンパイル時間 2,749 ms
コンパイル使用メモリ 164,608 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-14 00:05:06
合計ジャッジ時間 4,024 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

string in;

int main(){
	cin >> in;
	
	int ans = 0;
	bool allsame = 1;
	set<int> s, t, v;
	
	for(char c : in){
		if(c != in[0]) allsame = 0;
		s.insert(c - '0');
	}
	if(allsame){
		cout << in << endl;
		return 0;
	}
	for(int a : s) for(int b : s) if(a > b) v.insert(9 * (a - b));
	
	int g = 0;
	for(int i : v) g = __gcd(g, i);
	
	for(int y = g, i = 1; i * i <= y; i++) if(y % i == 0){
		t.insert(i);
		t.insert(y / i);
	}
	for(int x : t){
		int d = 0;
		for(char c : in){
			d *= 10; d += c - '0'; d %= x;
		}
		if(d == 0) ans = max(ans, x);
	}
	
	cout << ans << endl;
	
	return 0;
}
0