結果

問題 No.443 GCD of Permutation
ユーザー vjudge1
提出日時 2025-01-31 16:43:24
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 607 bytes
コンパイル時間 849 ms
コンパイル使用メモリ 63,448 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-01-31 16:43:26
合計ジャッジ時間 2,244 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e4+10; char s[N]; bool book[20];
int main() {
	//freopen("gcd.in","r",stdin);
	//freopen("gcd.out","w",stdout);
	ios::sync_with_stdio(false),cin.tie(nullptr);
	int n,k=0; cin>>(s+1),n=strlen(s+1);
	for(int i=1;i<=n;i++) book[s[i]-'0']=true;
	for(int i=1;i<=9;i++) for(int j=0;j<i;j++) if(book[i]&&book[j]) k=__gcd(k,9*(i-j));
	if(!k) return cout<<(s+1),0;
	for(int i=k;i>=1;i--) {
		if(k%i) continue;
		int r=0;
		for(int j=1;j<=n;j++) r=(r*10+s[j]-'0')%i;
		if(!r) return cout<<i,0;
	}
	return 0;
}
0