結果

問題 No.811 約数の個数の最大化
ユーザー DoneruDoneru
提出日時 2019-04-12 21:56:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 762 bytes
コンパイル時間 1,402 ms
コンパイル使用メモリ 153,012 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 20:06:31
合計ジャッジ時間 2,280 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 8 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,348 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 4 ms
4,348 KB
testcase_09 AC 7 ms
4,348 KB
testcase_10 AC 3 ms
4,352 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 30 ms
4,352 KB
testcase_14 AC 4 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
  int n,k;
  cin >> n >> k;

  vector<int> p;
  map<int,int> num;

  int tmp = n;

  for(int i = 2;i*i <= n;i++){
    if(tmp%i == 0){
      p.push_back(i);
      while(tmp%i==0){
	num[i]++;
	tmp /= i;
      }
    }
  }

  int ret = 0;
  int mxcnt = 0;

  for(int i = 2;i < n;i++){
    tmp = i;
    int cnt = 0;
    for(int j = 0;j < p.size();j++){
      for(int c = 0;c < num[p[j]];c++){
	if(tmp%p[j]==0){
	  cnt++;
	  tmp /= p[j];
	}else{
	  break;
	}
      }
    }

    if(cnt < k)continue;

    cnt = 0;
    for(int j = 2;j*j <= i;j++){
      if(i % j == 0){
	if(j*j == i)cnt++;
	else cnt += 2;
      }
    }
    if(mxcnt < cnt){
      mxcnt = cnt;
      ret = i;
    }
  }

  cout << ret << endl;
}
0