結果

問題 No.443 GCD of Permutation
ユーザー simezi_tansimezi_tan
提出日時 2016-12-03 15:29:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 1,024 bytes
コンパイル時間 1,859 ms
コンパイル使用メモリ 165,156 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 01:29:20
合計ジャッジ時間 3,172 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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