結果
| 問題 |
No.811 約数の個数の最大化
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-20 00:31:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 10 ms / 2,000 ms |
| コード長 | 930 bytes |
| コンパイル時間 | 733 ms |
| コンパイル使用メモリ | 77,916 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-24 08:46:59 |
| 合計ジャッジ時間 | 1,445 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
コンパイルメッセージ
main.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
6 | main()
| ^~~~
main.cpp: In function 'int main()':
main.cpp:68:15: warning: 'M' may be used uninitialized [-Wmaybe-uninitialized]
68 | cout<<M<<endl;
| ^
main.cpp:38:13: note: 'M' was declared here
38 | int M,am=0;
| ^
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int N,K;
main()
{
cin>>N>>K;
int sn=N;
vector<int>a;
for(int i=2;i*i<=N;i++)
{
while(N%i==0)
{
a.push_back(i);
N/=i;
}
}
if(N>1)a.push_back(N);
vector<int>x;
for(int comb=(1<<K)-1;comb<1<<a.size();)
{
int now=1;
for(int j=0;j<a.size();j++)
{
if(comb>>j&1)
{
now*=a[j];
}
}
x.push_back(now);
int X=comb&-comb;
int y=comb+X;
comb=(comb&~y)/X>>1|y;
}
sort(x.begin(),x.end());
x.erase(unique(x.begin(),x.end()),x.end());
int M,am=0;
for(int i=1;i<sn;i++)
{
bool f=0;
for(int j=0;j<x.size();j++)
{
if(i%x[j]==0)
{
f=1;
break;
}
}
if(!f)continue;
int cnt=1,now=i;
for(int j=2;j*j<=now;j++)
{
if(now%j==0)
{
int ac=1;
while(now%j==0)
{
now/=j;
ac++;
}
cnt*=ac;
}
}
if(now>1)cnt*=2;
if(am<cnt)am=cnt,M=i;
}
cout<<M<<endl;
}