結果

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

ソースコード

diff #

# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 # define int long long
# define lc u << 1
# define rc u << 1 | 1
# define fi first
# define se second
const int N = 15;

string n;
bool hav[N];
signed main ()
{
//	freopen ("gcd.in", "r", stdin); freopen ("gcd.out", "w", stdout);
    cin >> n;
    for (auto c : n) hav[c - '0'] = 1;
    int g = 0;
    for (int i = 0; i <= 9; i ++ )
    {
    	for (int j = 0; j < i; j ++ )
    	{
    		if (hav[i] && hav[j])
                g = __gcd (g, 9 * (i - j));
        }
    }
    if (!g) return cout << n << "\n", 0;
    for (int i = g; i >= 0; i -- )
    {
    	if (g % i == 0)
    	{
    		int t = 0;
    		for (auto c : n) t = (t * 10 % i + (c - '0')) % i;
    		if (!t) return printf ("%lld\n", i), 0;
		}
	}
    return 0;
}
0