結果

問題 No.368 LCM of K-products
ユーザー kongarishisyamokongarishisyamo
提出日時 2016-04-30 00:16:31
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,449 bytes
コンパイル時間 784 ms
コンパイル使用メモリ 63,080 KB
実行使用メモリ 40,912 KB
最終ジャッジ日時 2024-04-15 07:49:22
合計ジャッジ時間 7,137 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;

#define mod (int)(pow(10.0,9)+7)

long long pn;
long long sk[1000];
long long p[4000];
long long hurui[40000];
long long a[1000];
long long ap[1000][4000];
long long sp[4000]={0};
long long sp2[4000];
bool f=false;
long long N,K;

void search(long long i,long long k){
	if(k==K){
		for(long long j=0;j<pn;j++){
			sp2[j]=0;
			for(long long q=0;q<K;q++){
				sp2[j]+=ap[sk[q]][j];
			}
			sp[j]=max(sp2[j],sp[j]);
		}
		return;
	}
	for(long long j=i;j<N;j++){
		sk[k]=j;
		search(j+1,k+1);
	}
}

long long strong_pow(long long n,long long k){
	n%=mod;
	if(k==0) return 1%mod;
	else if(k%2==0){
		long long num=strong_pow(n,k/2)%mod;
		return num*num%mod;
	}
	else{
		long long num=strong_pow(n,k-1)%mod;
		return num*n%mod;
	}
}

int main(){

	for(long long i=0;i<40000;i++) hurui[i]=0;

	for(long long i=2;i<=sqrt(pow(10.0,9));i++){
		if(hurui[i]==0){
			for(long long j=i;j<=sqrt(pow(10.0,9));j+=i){
				hurui[j]=1;
			}
			p[pn]=i;
			pn++;
		}
	}

	cin>>N>>K;
	for(long long i=0;i<N;i++){
		cin>>a[i];
	}
	for(long long i=0;i<N;i++){
		long long tmp=a[i];
		for(long long j=0;j<pn;j++){
			long long c=0;
			while(tmp!=0&&tmp%p[j]==0){
				tmp/=p[j];
				c++;
			}
			ap[i][j]=c;
		}
	}

	search(0,0);

	long long ans=1,tmp1;
	for(long long i=0;i<pn;i++){
		tmp1=strong_pow(p[i],sp[i]);
		tmp1%=mod;
		ans*=tmp1;
		ans%=mod;
		cout<<ans<<endl;
	}

	cout<<ans<<endl;
}
0