結果
| 問題 |
No.811 約数の個数の最大化
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-04 22:25:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 23 ms / 2,000 ms |
| コード長 | 1,974 bytes |
| コンパイル時間 | 865 ms |
| コンパイル使用メモリ | 87,420 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-18 17:30:36 |
| 合計ジャッジ時間 | 1,500 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
コンパイルメッセージ
main.cpp: In function 'll primediv2(ll)':
main.cpp:62:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
62 | for(auto [v,num]:res){
| ^
main.cpp: In function 'int main()':
main.cpp:89:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
89 | for(auto [v,num]:primenum){
| ^
ソースコード
#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<int,int> P;
typedef pair<int,P> PP;
const ll MOD=1e9+7;
vector<pair<ll,ll>> primediv(ll n){
vector<pair<ll,ll>> res;
for(ll p=2;p*p<=n;p++){
if(n%p==0){
pair<ll,ll> tmp;
tmp.first=p,tmp.second=0;
while(n%p==0){
n/=p;
tmp.second++;
}
res.push_back(tmp);
}
}
if(n>1){
res.emplace_back(n,1);
}
return res;
}
ll primediv2(ll n){
vector<pair<ll,ll>> res;
for(ll p=2;p*p<=n;p++){
if(n%p==0){
pair<ll,ll> tmp;
tmp.first=p,tmp.second=0;
while(n%p==0){
n/=p;
tmp.second++;
}
res.push_back(tmp);
}
}
if(n>1){
res.emplace_back(n,1);
}
ll cnt=1;
for(auto [v,num]:res){
cnt*=(num+1);
}
return cnt;
}
int main(){
int N,K;
cin>>N>>K;
auto primenum=primediv(N);
ll maxnum=0;//約数の個数のmax
ll ans=0;
for(ll i=1;i<N;i++){
//cout<<"i="<<i<<endl;
ll cntnum=1;
ll k=0;
ll tmpi=i;
for(auto [v,num]:primenum){
if(tmpi%v==0){
ll t=0;
while(tmpi%v==0){
t++;
tmpi/=v;
}
k+=min(t,num);
}
}
if(k>=K){
ll candnum=primediv2(i);
if(maxnum<candnum){
ans=i;
maxnum=candnum;
}
//cout<<"ans="<<ans<<endl;
//cout<<"maxnum="<<maxnum<<endl;
}
}
cout<<ans<<endl;
}