結果

問題 No.811 約数の個数の最大化
ユーザー 👑 nu50218nu50218
提出日時 2019-04-17 11:47:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 2,962 bytes
コンパイル時間 1,888 ms
コンパイル使用メモリ 184,836 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 07:20:24
合計ジャッジ時間 2,926 ms
ジャッジサーバーID
(参考情報)
judge9 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
#define pow2(x) ((long long)((long long)1<<x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */

vector<long long> PrimeFactorize(long long n){
  vector<bool> prime(round(sqrt(n))+1,1);
  vector<long long> ans;
  for(long long i=2;i*i<=n;i++){
    if(prime[i]){
      for(long long j=2*i;j*j<=n;j+=i){
        prime[j] = 0;
      }
      while(n%i==0){
        ans.push_back(i);
        n /= i;
      }
    }
  }
  if(n != 1)ans.push_back(n);
  return ans;
}

long long GCD(long long a, long long b){long long q;while(b){q=a%b;a=b;b=q;}return a;}

/* main */

signed main(){
    ll N,K;
    cin >> N >> K;
    ll ans = 0;
    ll MAX = -1;
    FOR(i,1,N){
        ll tmp = GCD(i,N);
        if(PrimeFactorize(tmp).size() >= K){
            vl v = PrimeFactorize(i);
            map<int,int> m;
            set<int> s;
            for(auto x:v){
                m[x]++;
                s.insert(x);
            }
            ll tmp2 = 1;
            for(auto x:s){
                tmp2 *= m[x]+1;
            }
            if(tmp2 > MAX){
                MAX = tmp2;
                ans = i;
            }
        }
    }
    cout << ans << endl;
}
0