結果

問題 No.368 LCM of K-products
ユーザー kotatsugamekotatsugame
提出日時 2020-02-22 07:48:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 364 ms / 2,000 ms
コード長 700 bytes
コンパイル時間 732 ms
コンパイル使用メモリ 76,496 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-17 22:12:28
合計ジャッジ時間 6,946 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 255 ms
6,812 KB
testcase_01 AC 364 ms
6,944 KB
testcase_02 AC 347 ms
6,940 KB
testcase_03 AC 352 ms
6,944 KB
testcase_04 AC 352 ms
6,940 KB
testcase_05 AC 349 ms
6,940 KB
testcase_06 AC 4 ms
6,940 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 4 ms
6,940 KB
testcase_09 AC 4 ms
6,944 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 4 ms
6,940 KB
testcase_13 AC 167 ms
6,944 KB
testcase_14 AC 273 ms
6,940 KB
testcase_15 AC 302 ms
6,944 KB
testcase_16 AC 265 ms
6,940 KB
testcase_17 AC 222 ms
6,940 KB
testcase_18 AC 316 ms
6,940 KB
testcase_19 AC 67 ms
6,940 KB
testcase_20 AC 217 ms
6,940 KB
testcase_21 AC 45 ms
6,944 KB
testcase_22 AC 303 ms
6,944 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 4 ms
6,944 KB
testcase_25 AC 4 ms
6,940 KB
testcase_26 AC 3 ms
6,940 KB
testcase_27 AC 4 ms
6,940 KB
testcase_28 AC 4 ms
6,944 KB
testcase_29 AC 4 ms
6,944 KB
testcase_30 AC 5 ms
6,940 KB
testcase_31 AC 5 ms
6,948 KB
testcase_32 AC 4 ms
6,940 KB
testcase_33 AC 122 ms
6,940 KB
testcase_34 AC 352 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int N,K,A[1000];
long mod=1e9+7,ans=1;
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
main()
{
	cin>>N>>K;
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=2;i*i<=1000000000;i++)
	{
		vector<int>cnt(N);
		for(int j=0;j<N;j++)
		{
			while(A[j]%i==0)
			{
				A[j]/=i;
				cnt[j]++;
			}
		}
		sort(cnt.begin(),cnt.end());
		int x=0;
		for(int j=0;j<K;j++)x+=cnt[N-j-1];
		ans=ans*power(i,x)%mod;
	}
	for(int i=0;i<N;i++)
	{
		if(A[i]==1)continue;
		int a=A[i];
		int x=0;
		for(int j=0;j<N;j++)
		{
			if(A[j]==a)
			{
				A[j]=1;
				x++;
			}
		}
		ans=ans*power(a,x<K?x:K)%mod;
	}
	cout<<ans<<endl;
}
0