結果

問題 No.36 素数が嫌い!
ユーザー 綾地寧々綾地寧々
提出日時 2015-07-22 18:27:58
言語 PHP
(8.3.4)
結果
TLE  
実行時間 -
コード長 681 bytes
コンパイル時間 1,147 ms
コンパイル使用メモリ 18,672 KB
実行使用メモリ 19,300 KB
最終ジャッジ日時 2023-09-22 21:14:52
合計ジャッジ時間 13,389 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,383 ms
18,948 KB
testcase_01 AC 122 ms
19,240 KB
testcase_02 AC 16 ms
19,124 KB
testcase_03 AC 16 ms
18,984 KB
testcase_04 AC 16 ms
19,036 KB
testcase_05 AC 28 ms
19,224 KB
testcase_06 AC 35 ms
19,180 KB
testcase_07 AC 36 ms
19,284 KB
testcase_08 AC 16 ms
19,200 KB
testcase_09 AC 16 ms
18,972 KB
testcase_10 AC 18 ms
19,084 KB
testcase_11 AC 1,959 ms
19,132 KB
testcase_12 TLE -
testcase_13 TLE -
testcase_14 AC 37 ms
19,300 KB
testcase_15 AC 16 ms
19,164 KB
testcase_16 AC 16 ms
18,988 KB
testcase_17 AC 16 ms
19,168 KB
testcase_18 AC 16 ms
19,212 KB
testcase_19 AC 253 ms
19,012 KB
testcase_20 AC 209 ms
19,164 KB
testcase_21 AC 789 ms
19,124 KB
testcase_22 AC 105 ms
19,108 KB
testcase_23 AC 52 ms
19,180 KB
testcase_24 AC 867 ms
19,256 KB
testcase_25 AC 1,043 ms
19,256 KB
testcase_26 AC 2,086 ms
19,120 KB
testcase_27 AC 121 ms
19,164 KB
testcase_28 AC 2,046 ms
19,168 KB
testcase_29 AC 59 ms
19,120 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
$n = trim(fgets(STDIN));
$gmp_n = gmp_init($n);
$fact_time = 0;
$i = 1;
while ( $fact_time <= 2 ) {
	if ( gmp_cmp($gmp_n, gmp_init(1)) == 0 ) {
		break;
	}
	$is_prime = 1;
	for ( $i=($i+1); gmp_cmp(gmp_init($i*$i),$gmp_n)<0; $i++ ) {
		if ( gmp_cmp(gmp_div_r($gmp_n, gmp_init($i)), gmp_init(0)) == 0 ) {
			$is_prime = 0;
			break;
		}
	}
	if ( $is_prime ) {
		$fact_time++;
		break;
	}
	while ( gmp_cmp(gmp_div_r($gmp_n, gmp_init($i)), gmp_init(0)) == 0 ) {
		$gmp_n = gmp_div_q($gmp_n, gmp_init($i));
		if ( $fact_time < PHP_INT_MAX )
			$fact_time++;
		if ( $fact_time > 2 ) {
			break;
		}
	}
}
if ( $fact_time > 2 ) {
	echo "YES".PHP_EOL;
}
else {
	echo "NO".PHP_EOL;
}
0