結果

問題 No.811 約数の個数の最大化
ユーザー 👑 tatyamtatyam
提出日時 2019-04-12 18:06:54
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 782 bytes
コンパイル時間 2,296 ms
コンパイル使用メモリ 200,448 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 09:40:15
合計ジャッジ時間 3,008 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 3 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 3 ms
4,352 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 4 ms
4,348 KB
testcase_14 AC 4 ms
4,352 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:30:13: 警告: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized]
   30 |     cout << ans << endl;
      |             ^~~
main.cpp:25:18: 備考: ‘ans’ はここで定義されています
   25 |     int max = 0, ans;
      |                  ^~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    assert(4 <= n && n <= 100000);
    int f = 0, N = n;
    vector<int> facter(n, 1), prime(n);
    for(int i = 2; i < n; i++) for(int j = i; j < n; j += i) facter[j]++;
    for(int i = 2; i * i <= n; i++) if(n % i == 0) {
        int p = 1;
        while(n % i == 0) {
            f++;
            p *= i;
            n /= i;
            for(int j = p; j < N; j += p) prime[j]++;
        }
    }
    if(n != 1) {
        f++;
        for(int i = n; i < N; i += n) prime[i]++;
    }
    assert(1 <= k && k <= 15 && k < f);
    int max = 0, ans;
    for(int i = 2; i < N; i++) if(prime[i] >= k && max < facter[i]) {
        max = facter[i];
        ans = i;
    }
    cout << ans << endl;
}
0