結果
問題 | No.811 約数の個数の最大化 |
ユーザー | dsm4up2c |
提出日時 | 2019-04-12 21:53:13 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 267 ms / 2,000 ms |
コード長 | 1,538 bytes |
コンパイル時間 | 979 ms |
コンパイル使用メモリ | 80,888 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-14 18:16:22 |
合計ジャッジ時間 | 2,848 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
#include <iostream> #include <string> #include <algorithm> #include <cstdio> #include <vector> #include <queue> #include <stack> #include <set> #include <map> #include <numeric> #include <cmath> using namespace std; typedef long long int ll; typedef pair<int,int> P; #define all(x) x.begin(),x.end() const ll mod = 1e9+7; const ll INF = 1e9; const ll MAXN = 1e9; map<int, int> prime_factor(int n) { map<int, int> res; for(int i = 2; i * i <= n; i++) { while(n % i == 0) { ++res[i]; n /= i; } } if (n != 1) { res[n] = 1; } return res; } int main() { int n,k; cin>>n>>k; map<int,int> factor_n = prime_factor(n); int ans = n,num = -1; int mi=1,cnt=0; int res = n; for(int i = 2; i*i <= n; i++){ if(factor_n.find(i)!=factor_n.end()){ while(res%i==0 && cnt<k){ res /= i; cnt++; mi *= i; } } } for(int i = n-1; i >=mi; i--){ map<int,int> factor_i = prime_factor(i); cnt = 0; res = 1; for(int j = 2; j*j <= n; j++){ if(factor_n.find(j) != factor_n.end() && factor_i.find(j) != factor_i.end()){ cnt += min(factor_n[j],factor_i[j]); } if(factor_i.find(j)!=factor_i.end()) res *= factor_i[j]+1; } if(cnt>=k && num<=res){ ans = i; num = res; } } cout <<ans<<endl; return 0; }