結果

問題 No.811 約数の個数の最大化
ユーザー tottoripapertottoripaper
提出日時 2019-04-12 21:37:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 1,132 bytes
コンパイル時間 1,411 ms
コンパイル使用メモリ 169,860 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 19:10:42
合計ジャッジ時間 2,233 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 15 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 8 ms
4,352 KB
testcase_09 AC 9 ms
4,352 KB
testcase_10 AC 6 ms
4,348 KB
testcase_11 AC 12 ms
4,348 KB
testcase_12 AC 5 ms
4,352 KB
testcase_13 AC 22 ms
4,348 KB
testcase_14 AC 15 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int gcd(int a, int b){
    if(b == 0){
        return a;
    }
    return gcd(b, a % b);
}

int f(int n){
    int c = 0;

    for(int i=2;i*i<=n;++i){
        while(n % i == 0){
            n /= i;
            c += 1;
        }
    }

    if(n > 1){
        c += 1;
    }

    return c;
}

int g(int n){
    int c = 1;

    for(int i=2;i*i<=n;++i){
        int d = 1;

        while(n % i == 0){
            n /= i;
            d += 1;
        }
        
        c *= d;
    }

    if(n > 1){
        c *= 2;
    }

    return c;
}

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

    int N, K;
    std::cin >> N >> K;

    auto p = std::make_tuple(0, 0);
    
    for(int i=1;i<N;++i){
        if(f(gcd(i, N)) >= K){
            p = std::min(p, std::make_tuple(-g(i), i));
        }
    }

    int m;
    std::tie(std::ignore, m) = p;

    std::cout << m << std::endl;
}
0