求一个mysql5.1判断34以下是否为素数的函数

求一个mysql5.1判断34以下是否为素数的函数,第1张

<?php

header("Content-type:text/htmlcharset=utf-8")

$count = 0//该变量用来统计素数个数,并初始化为0

echo "素数:"

for($i=2$i<34$i++)

{

for($j=2$j<=intval(sqrt($i))$j++)

{

if($i%$j==0)

{

$isPrime=false

break

}

$isPrime=true

}

if($isPrime)

{

$count = $count + 1//是素数,所以统计变量加1

echo $i ." "

}

}

echo "素数的个数为:".$count

?>

create proc dbo.Usp_IsSuShu(@No int)

as

begin

if @No <=1 

return 0

declare @maxV int, @Index int

set @maxV = @No -1

set @Index = 2

while @Index < @maxV

begin

declare @maxV2 int,@Index2 int

set @maxV2 = @maxV

set @Index2 = @Index

while @Index2 < @maxV2

begin

if @Index2 * @Index = @No

select 0

set @Index2 = @Index2 + 1

end

set @Index = @Index + 1

end

select 1

end 

dbo.ChkIntIsSuShu(13) -- 返回值1,表示素数,0表示非素数。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/zaji/8489002.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-17
下一篇2023-04-17

发表评论

登录后才能评论

评论列表(0条)

    保存