結果

問題 No.443 GCD of Permutation
ユーザー anubhavchk007anubhavchk007
提出日時 2024-01-12 04:17:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 642 bytes
コンパイル時間 1,908 ms
コンパイル使用メモリ 172,392 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-12 04:17:26
合計ジャッジ時間 5,677 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
}
0