結果

問題 No.811 約数の個数の最大化
ユーザー to10to10to10toto10to10to10to
提出日時 2019-04-13 18:42:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,059 bytes
コンパイル時間 2,645 ms
コンパイル使用メモリ 166,972 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 14:30:56
合計ジャッジ時間 2,630 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define PI (acos(-1))

vector<int> divisor(int n){
  vector<int> div;
  for(int i=1; i*i<=n; i++){
    if(n%i==0){
      div.push_back(i);
      if(i*i!=n){
        div.push_back(n/i);
      }
    }
  }
  return div;
}

int prime_factorize(int n){//nの素因数の数
  int tmp = n,cnt=0;
  for(int p=2; p*p<=tmp; p++){
    if(n%p!=0)continue;
    while(n%p==0){
      cnt++;
      n/=p;
    }
  }
  if(n!=1)return 0;
  return cnt;
}

int gcd(int a,int b){
  if(a<b){
    swap(a,b);
  }
  int r;
  while(b>0){
    r = a%b;
    a = b;
    b = r;
  }
  return a;
}

int main(){
  int n,k,ma=0,ans;
  cin >> n >> k;
  reps(i,1,n+1){
    int g = gcd(i,n);
    int p = prime_factorize(g);
    if(p >= k){
      int d = divisor(i).size();
      if(d > ma){
        ma = d;
        ans = i;
      }
    }
  }
  cout << ans << endl;
}
0