結果

問題 No.16 累乗の加算
ユーザー 綾地寧々綾地寧々
提出日時 2015-06-21 10:42:16
言語 PHP
(8.2.11)
結果
AC  
実行時間 3,256 ms / 5,000 ms
コード長 1,108 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 18,700 KB
実行使用メモリ 211,896 KB
最終ジャッジ日時 2023-09-08 11:42:57
合計ジャッジ時間 31,830 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 431 ms
50,120 KB
testcase_01 AC 429 ms
50,176 KB
testcase_02 AC 3,256 ms
211,896 KB
testcase_03 AC 2,893 ms
197,860 KB
testcase_04 AC 2,468 ms
174,092 KB
testcase_05 AC 3,009 ms
202,340 KB
testcase_06 AC 2,894 ms
198,276 KB
testcase_07 AC 2,051 ms
146,764 KB
testcase_08 AC 3,053 ms
202,148 KB
testcase_09 AC 1,800 ms
133,168 KB
testcase_10 AC 1,523 ms
118,980 KB
testcase_11 AC 3,210 ms
210,964 KB
testcase_12 AC 3,148 ms
210,712 KB
testcase_13 AC 16 ms
19,268 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
$start = microtime(TRUE);

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_pow($gmp_pow_temp, 2);
	$exp_sum_value[$i] = gmp_intval(gmp_div_r($gmp_pow_temp, gmp_init(RESULT_DIV_VALUE)));
}
$exp_sum_value_max_index = ($i>>1);
$gmp_sum = 0;
foreach ( $exp_member_array as $index => $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_mul($gmp_sum_temp, $exp_sum_value[$i]);
		}
		$i >>= 1;
	}
	$gmp_sum_temp = gmp_div_r($gmp_sum_temp, gmp_init(RESULT_DIV_VALUE));
	$gmp_sum += gmp_intval($gmp_sum_temp);
	$gmp_sum %= RESULT_DIV_VALUE;
}

echo gmp_strval($gmp_sum).PHP_EOL;
$exec = microtime(TRUE) - $start;
fprintf(STDERR, "EXEC: {$exec} seconds\n");
fprintf(STDERR, "MEM: %d KiB\n", memory_get_peak_usage(TRUE)/1024);
0