Created
November 6, 2013 16:05
-
-
Save kazua/7338810 to your computer and use it in GitHub Desktop.
Project Euler Problem 7(PHP)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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