結果
問題 |
No.443 GCD of Permutation
|
ユーザー |
|
提出日時 | 2025-01-25 16:27:10 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 711 bytes |
コンパイル時間 | 638 ms |
コンパイル使用メモリ | 82,408 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2025-01-25 16:27:13 |
合計ジャッジ時間 | 1,507 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 28 |
ソースコード
#include <iostream> #include <numeric> using namespace std; bool appear[15]; bool factor(string s, int mod) { int x = 0; for(char c : s) { x = x * 10 + (c - '0'); x %= mod; } return !x; } int main() { string n; cin >> n; for(auto c : n) { appear[c - '0'] = true; } int g = 0; for(int i = 0; i <= 9; i++) { for(int j = 0; j < i; j++) { if(appear[i] and appear[j]) { g = gcd(g, 9 * (i - j)); } } } if(!g) { cout << n << endl; return 0; } for(int i = g; i >= 1; i--) { if(g % i == 0 and factor(n, i)) { cout << i; return 0; } } }