Skip to content

Instantly share code, notes, and snippets.

@savasdersimcelik
Created November 22, 2017 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save savasdersimcelik/e7efea6e4f7a81b85fde175c94ee5926 to your computer and use it in GitHub Desktop.
Save savasdersimcelik/e7efea6e4f7a81b85fde175c94ee5926 to your computer and use it in GitHub Desktop.
PHP İkiz Asal Sayılar Algoritması
<?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