結果

問題 No.811 約数の個数の最大化
ユーザー kotatsugamekotatsugame
提出日時 2019-04-20 00:31:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 930 bytes
コンパイル時間 686 ms
コンパイル使用メモリ 76,524 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 17:06:58
合計ジャッジ時間 1,633 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 4 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 9 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
      |             ^

ソースコード

diff #

#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;
}
0