메뉴 건너뛰기

app

[PHP] prime number generator

박영식2010.05.25 18:42조회 수 4102댓글 0

  • 1
    • 글자 크기
어디서 찾았는지 기억이 안난다.

원리는 1부터 입력값까지의 소수를 구하는 소스이다.

풀 소스는 zip 파일로 첨부한다.

약간 변형하면 임의의 범위에서의 소수를 생성할 수 있게 할 수 있다.

범위가 너무 크면 maximum execution time을 초과해 강제 종료될 수도 있다.

 This software is developed and copyrighted by Xantus WEBdevelopment.

if ($_POST['count'] != ""){
 if (is_numeric($_POST['count'])){
  $time_start = microtime(1);
  $x = $_POST['count'];
  for($i=1;$i<=$x;$i++) {
   $f=sqrt($i);
   for($z=1;$z<=$f;$z++) {
    $y=$i%$z;
    if($y==0){
     $l++;
    }
    if($l>=2){
     break;
    }
   }
   if ($l<=1){
    echo "$i, ";
    $b++;
   }
   $l=0;
  }
  $time_end = microtime(1);
  $time = $time_end - $time_start;
  echo "<br><b>[ Found first $x prime numbers in $time seconds ]</b>";
 }
 else
 {
  echo "<br><b>Please enter a number!</b>";
 }
}
박영식 (비회원)
  • 1
    • 글자 크기
[xcode] NSMutableURLRequest POST전송과 결과 XML 출력(파싱포함) (by 박영식) [jsp] 한글 인코딩 처리 (by 박영식)

댓글 달기

박영식
2010.09.09 조회 4793
박영식
2010.05.25 조회 4102
박영식
2010.01.14 조회 4971
박영식
2009.09.21 조회 4147
박영식
2008.08.18 조회 6064
박영식
2008.08.17 조회 4194
박영식
2008.07.24 조회 4623
박영식
2008.07.23 조회 8003
박영식
2008.07.22 조회 3352
박영식
2008.04.11 조회 2199
박영식
2008.01.20 조회 2041
박영식
2007.12.23 조회 3224
첨부 (1)
prime-number-calculator.zip
3.6KB / Download 39
위로