結果

問題 No.811 約数の個数の最大化
ユーザー mikianaaamikianaaa
提出日時 2020-09-09 20:54:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 1,572 bytes
コンパイル時間 1,736 ms
コンパイル使用メモリ 168,116 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-22 10:45:52
合計ジャッジ時間 3,051 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 22 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 4 ms
4,384 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 11 ms
4,380 KB
testcase_09 AC 13 ms
4,380 KB
testcase_10 AC 8 ms
4,380 KB
testcase_11 AC 18 ms
4,376 KB
testcase_12 AC 7 ms
4,380 KB
testcase_13 AC 40 ms
4,376 KB
testcase_14 AC 22 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12.2.0/istream:39,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/sstream:38,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/complex:45,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/ccomplex:39,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/x86_64-pc-linux-gnu/bits/stdc++.h:54,
         次から読み込み:  main.cpp:2:
メンバ関数 ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]’ 内,
    inlined from ‘int main()’ at main.cpp:71:13:
/usr/local/gcc7/include/c++/12.2.0/ostream:202:25: 警告: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized]
  202 |       { return _M_insert(__n); }
      |                ~~~~~~~~~^~~~~
main.cpp: 関数 ‘int main()’ 内:
main.cpp:59:16: 備考: ‘ans’ はここで定義されています
   59 |     ll en = 0, ans;
      |                ^~~

ソースコード

diff #

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)n - 1; i > -1; i--)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

int N, K;
pll prime_factorize(long long N) {
    ll res1 = 0, res2 = 1;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0)
            continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res1 += ex;
        res2 *= (ex + 1);
    }

    // 最後に残った数について
    if (N != 1) {
        res1 += 1;
        res2 *= 2;
    }
    return {res1, res2};
}

long long GCD(long long a, long long b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> K;
    vector<ll> tmp;
    for (int i = 1; i < N; i++) {
        int gcd = GCD(i, N);
        pll pri = prime_factorize(gcd);
        if (pri.first >= K)
            tmp.push_back(i);
    }

    ll en = 0, ans;
    rep(i, tmp.size()) {
        pll pri = prime_factorize(tmp[i]);
        if (pri.second > en) {
            en = pri.second;
            ans = tmp[i];
        } else if (pri.second == en) {
            if (tmp[i] < ans)
                ans = tmp[i];
        }
    }

    cout << ans << endl;
    return 0;
}
0