結果

問題 No.16 累乗の加算
ユーザー 綾地寧々綾地寧々
提出日時 2015-06-23 08:39:47
言語 PHP
(8.3.4)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 917 bytes
コンパイル時間 1,149 ms
コンパイル使用メモリ 18,644 KB
実行使用メモリ 19,284 KB
最終ジャッジ日時 2023-09-08 11:41:22
合計ジャッジ時間 2,180 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
18,992 KB
testcase_01 AC 17 ms
19,048 KB
testcase_02 AC 17 ms
19,284 KB
testcase_03 AC 17 ms
19,184 KB
testcase_04 AC 17 ms
19,188 KB
testcase_05 AC 16 ms
19,208 KB
testcase_06 AC 17 ms
19,188 KB
testcase_07 AC 17 ms
19,240 KB
testcase_08 AC 17 ms
19,264 KB
testcase_09 AC 17 ms
19,188 KB
testcase_10 AC 17 ms
19,176 KB
testcase_11 AC 17 ms
18,996 KB
testcase_12 AC 17 ms
19,184 KB
testcase_13 AC 17 ms
19,228 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
define("EXP_MAX", 100000000);
define("RESULT_DIV_VALUE", 1000003);

list($x, $n) = explode(" ",trim(fgets(STDIN)));
$exp_member_array = explode(" ",trim(fgets(STDIN)));

$exp_sum_value = array();
$exp_sum_value[1] = intval($x);
$gmp_pow_temp = gmp_init($exp_sum_value[1]);
for ( $i=2; $i<=EXP_MAX; $i<<=1 ) {
	$gmp_pow_temp = gmp_mul($gmp_pow_temp, gmp_div_r($gmp_pow_temp, gmp_init(RESULT_DIV_VALUE)));
	$exp_sum_value[$i] = gmp_intval(gmp_div_r($gmp_pow_temp, gmp_init(RESULT_DIV_VALUE)));
}
$exp_sum_value_max_index = ($i>>1);
$sum = 0;
foreach ( $exp_member_array as &$exp ) {
	$i = $exp_sum_value_max_index;
	$gmp_sum_temp = gmp_init(1);
	while ( $exp > 0 ) {
		while ( $exp >= $i ) {
			$exp -= $i;
			$gmp_sum_temp = gmp_div_r(gmp_mul($gmp_sum_temp, $exp_sum_value[$i]), gmp_init(RESULT_DIV_VALUE));
		}
		$i >>= 1;
	}
	$sum += gmp_intval($gmp_sum_temp);
	$sum %= RESULT_DIV_VALUE;
}

echo $sum.PHP_EOL;
0