--- プログラム ---

BEGIN{
print "1 : prime number"
print "0 : not prime number"
print ""
num=9999991
print "number = " num
print "answer = " prmch(num)
}

function prmch(n, ipn)
{ 
ipn=1
if(n<2)
{ 
    ipn=0
} 
else if(n==2)
{  
} 
else if(n%2==0)
{  
    ipn=0
}  
else
{  
    ipn=prmch2(n)
}  
return ipn
} 
 
function prmch2(n, ipn)
{ 
ipn=1
tmp=sqrt(n)
for (i=3;i<tmp+1;i=i+2)
{ 
    if(n%i==0)
    { 
        ipn=0
        break
    }  
}  
return ipn
}


--- 実行結果 ---

1 : prime number
0 : not prime number

number = 9999991
answer = 1






戻る