結果
問題 |
No.443 GCD of Permutation
|
ユーザー |
|
提出日時 | 2024-01-12 04:17:16 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 642 bytes |
コンパイル時間 | 1,686 ms |
コンパイル使用メモリ | 172,148 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-27 20:43:48 |
合計ジャッジ時間 | 4,810 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 11 RE * 17 |
ソースコード
#include <iostream> #include "bits/stdc++.h" #include <unordered_set> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main() { std::string N; std::cin >> N; std::unordered_set<int> S; for (char c : N) { S.insert(c - '0'); } if (S.size() == 1) { std::cout << N << std::endl; } else { int G = 0; for (int y : S) { for (int x : S) { if (y > x) { G = __gcd(G, 9 * (y - x)); } } } std::cout << __gcd(stoi(N), G) << std::endl; } return 0; }