結果

問題 No.811 約数の個数の最大化
ユーザー utouto97utouto97
提出日時 2019-08-20 15:55:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 1,214 bytes
コンパイル時間 1,620 ms
コンパイル使用メモリ 158,304 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 02:25:54
合計ジャッジ時間 2,347 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

int gcd(int a, int b){
  return b ? gcd(b, a%b) : a;
}

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

  int ans = 0, div = 0;
  rep(i, 1, n){
    int g = gcd(n, i);

    int tmp = 0;
    rep(j, 2, g/j+1){
      int c = 0;
      while(g%j == 0){
        c++;
        g /= j;
      }
      tmp += c;
    }
    if(g != 1) tmp++;

//    cout << i << " " << tmp << endl;
    if(tmp < k) continue;

    tmp = 1;
    int t = i;
    rep(j, 2, t/j+1){
      int c = 0;
      while(t%j == 0){
        c++;
        t /= j;
      }
      tmp *= (c+1);
    }
    if(t != 1) tmp *= 2;
    
    if(chmax(div, tmp)){
      ans = i;
    }
//    cout << i << " " << tmp << " " << ans << endl;
  }

  cout << ans << endl;

  return 0;
}
0