結果

問題 No.811 約数の個数の最大化
ユーザー hamrayhamray
提出日時 2019-06-16 01:50:28
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,371 bytes
コンパイル時間 1,415 ms
コンパイル使用メモリ 113,060 KB
実行使用メモリ 10,784 KB
最終ジャッジ日時 2024-05-01 11:34:27
合計ジャッジ時間 7,220 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 11 ms
5,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 TLE -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 TLE -
testcase_14 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <climits>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
struct Edge {
    int to, cost;
    Edge(int to, int cost): to(to), cost(cost) {}
};

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<Edge>> AdjList;
AdjList graph;

const int INF = 100000000;

LL N, M;
map<int, int> prime;
int main() {
    //cout << fixed << setprecision(15);

    int N, K; cin >> N >> K;
    int n = N;
    vector<int> v;
    for(int i=2; i<=N; ++i){
        while(N%i == 0){
            v.push_back(i);
            prime[i]++;
            N /= i;
        }
    }

    if(N != 1) {
        v.push_back(N);
        prime[N]++;
    }

    LL t = 1;
    int idx=0;
    for(auto e: prime){
        if(idx>=K-1) break;
        for(int i=0; i<e.second-1; ++i){
            if(idx>=K-1) break;
            t *= e.first;
            idx++;
        }
    }
    vector<int> v2;
    for(int i=n-1; i>=1; --i) if(i%t == 0) v2.push_back(i);

    int ans = 0;
    LL num = 0;
    for(int i=0; i<v2.size(); ++i){
        t = v2[i];
        map<int, LL> mp;
        for(int j=2; j<=t; ++j){
            while(t%j==0){
                mp[j]++;
                t/=j;
            }
        }

        t = 1;
        for(auto e: mp){
            t *= (e.second+1);
        }

        if(num < t){
            num = t;
            ans = v2[i];
        }else if(num == t){
            if(ans > v2[i]) {
                ans = v2[i];
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0