Skip to content

Instantly share code, notes, and snippets.

@kazua
Created November 6, 2013 16:05
Show Gist options
  • Save kazua/7338810 to your computer and use it in GitHub Desktop.
Save kazua/7338810 to your computer and use it in GitHub Desktop.
Project Euler Problem 7(PHP)
<?php
//http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%207
//write kazua
$p = array();
$i = 2;
$f = function ($value) {
global $p;
$a = range(1, (int) sqrt($value));
foreach ($a as $v) if ($v !== 1 && $value % $v === 0) return false;
$p[] = $value;
return true;
};
while (count($p) < 10001) {
$f($i);
$i++;
}
echo end($p);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment