結果

問題 No.368 LCM of K-products
ユーザー FF256grhyFF256grhy
提出日時 2016-04-30 04:45:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 1,278 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 23,936 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-23 21:12:09
合計ジャッジ時間 1,461 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
4,348 KB
testcase_01 AC 33 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 11 ms
4,348 KB
testcase_04 AC 4 ms
4,348 KB
testcase_05 AC 97 ms
4,348 KB
testcase_06 AC 0 ms
4,348 KB
testcase_07 AC 0 ms
4,348 KB
testcase_08 AC 0 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 0 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 7 ms
4,348 KB
testcase_14 AC 12 ms
4,348 KB
testcase_15 AC 13 ms
4,348 KB
testcase_16 AC 11 ms
4,348 KB
testcase_17 AC 10 ms
4,348 KB
testcase_18 AC 14 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 10 ms
4,348 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 14 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 0 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 0 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 1 ms
4,348 KB
testcase_33 AC 5 ms
4,348 KB
testcase_34 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:60:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   60 |         scanf("%d%d", &n, &k);
      |         ~~~~~^~~~~~~~~~~~~~~~
main.cpp:61:43: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   61 |         for(int i = 0; i < n; i++) { scanf("%d", &a[i]); }
      |                                      ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

#define MOD 1000000007

int n, k, a[1000];

int tree[8000 * 19][2], t_ptr = 1;
int array[8001][30], a_ptr = 1;

long long int ans = 1;

void add(int v, int e) {
	int p = 0;
	for(int i = 30 - 1; 0 <= i; i--) {
		int &pp = tree[p][ (v >> i) % 2 ];
		if(pp == 0) {
			if(i != 0) {
				pp = t_ptr;
				t_ptr++;
			} else {
				pp = a_ptr;
				a_ptr++;
			}
		}
		p = pp;
	}
	array[p][e]++;
	
	return;
}

int power(int x, int y) {
	if(y == 0) { return 1; }
	return x * power(x, y - 1);
}

void prod(int v, int p) {
	int c = 0;
	for(int i = 30 - 1; 0 <= i; i--) {
		for(int j = 0; j < array[p][i]; j++) {
			ans *= power(v, i);
			ans %= MOD;
			c++;
			if(c == k) { return; }
		}
	}
	return;
}

void search(int p, int d, int v) {
	if(d == -1) { prod(v, p); return; }
	
	if(tree[p][0] != 0) { search(tree[p][0], d - 1, v); }
	if(tree[p][1] != 0) { search(tree[p][1], d - 1, v + (1 << d)); }
	
	return;
}

int main() {
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n; i++) { scanf("%d", &a[i]); }
	
	for(int i = 0; i < n; i++) {
		for(int j = 2; 1 < a[i]; j++) {
			if(a[i] < j * j) { add(a[i], 1); break; }
			
			int e = 0;
			while(a[i] % j == 0) { a[i] /= j; e++; }
			if(e) { add(j, e); }
		}
	}
	
	search(0, 30 - 1, 0);
	
	printf("%lld\n", ans);
	
	return 0;
}
0