結果

問題 No.152 貯金箱の消失
ユーザー happy-beanshappy-beans
提出日時 2017-03-18 00:14:55
言語 PHP
(8.3.4)
結果
AC  
実行時間 90 ms / 5,000 ms
コード長 610 bytes
コンパイル時間 707 ms
コンパイル使用メモリ 12,020 KB
実行使用メモリ 12,336 KB
最終ジャッジ日時 2023-09-17 19:27:08
合計ジャッジ時間 1,274 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
12,268 KB
testcase_01 AC 7 ms
12,244 KB
testcase_02 AC 8 ms
12,252 KB
testcase_03 AC 7 ms
12,220 KB
testcase_04 AC 8 ms
12,204 KB
testcase_05 AC 9 ms
12,336 KB
testcase_06 AC 9 ms
12,224 KB
testcase_07 AC 20 ms
12,296 KB
testcase_08 AC 89 ms
12,268 KB
testcase_09 AC 90 ms
12,228 KB
testcase_10 AC 70 ms
12,304 KB
testcase_11 AC 42 ms
12,288 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
// No. 152

$l = trim(fgets(STDIN));

$sum = floor($l / 4);
$count = 0;

$p = 2;
$q = 1;
$count = 0;
while ((2*$p*($p+$q)) <= $sum) {


  while ($p > $q) {
    if (getGCD($p, $q) == 1) {
      $a = pow($p, 2) - pow($q, 2);
      $b = 2 * $p * $q;
      $c = pow($p, 2) + pow($q, 2);

      $count++;
    }

    $q += 2;
    if ((2*$p*($p+$q)) > $sum) break;
  }
  $p++;
  $q = 1 + ($p % 2);
}

echo $count.PHP_EOL;
return;

// ---------------------- //
function getGCD($a, $b)
{
  if ($a < $b) {
    return getGCD($b, $a);
  }
  else {
    $m = $a % $b;
    return ($m == 0) ? $b : getGCD($b, $m);
  }
}
0