Created
November 22, 2017 18:12
-
-
Save savasdersimcelik/e7efea6e4f7a81b85fde175c94ee5926 to your computer and use it in GitHub Desktop.
PHP İkiz Asal Sayılar Algoritması
This file contains 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 | |
/** | |
* Author : Savaş Dersim ÇELİK | |
* Version: 1.0.0 | |
* Web: http://webinyo.com | |
* Mail: savasdersimcelik@gmail.com | |
* Description : PHP İkiz Sayı Algoritması | |
*/ | |
set_time_limit(0); | |
function asal($sayi) | |
{ | |
$kok=sqrt($sayi); | |
if ($sayi == 1 || $sayi == 0) { | |
return false; | |
} | |
for ($i=2; $i<=$kok; $i++){ | |
if($sayi % $i==0) return false; | |
} | |
return true; | |
} | |
function ikizSayi($param) | |
{ | |
$ilk = $param; | |
$iki = $param+2; | |
if (asal($ilk) && asal($iki)) { | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
$sayac = 0; | |
for ($i=1; $i < 100000; $i++) { | |
if (ikizSayi($i)) { | |
$sayac++; | |
} | |
} | |
echo $sayac; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment