Jump to content

Coprimes: Difference between revisions

add FreeBASIC
(Added Algol W)
(add FreeBASIC)
Line 439:
{ 60 15 }
{ 21 22 25 31 143 } Coprime
</pre>
 
=={{header|FreeBASIC}}==
<lang freebasic>function gcdp( a as uinteger, b as uinteger ) as uinteger
'returns the gcd of two positive integers
if b = 0 then return a
return gcdp( b, a mod b )
end function
 
function gcd(a as integer, b as integer) as uinteger
'wrapper for gcdp, allows for negatives
return gcdp( abs(a), abs(b) )
end function
 
function is_coprime( a as integer, b as integer ) as boolean
return (gcd(a,b)=1)
end function
 
print is_coprime(21,15)
print is_coprime(17,23)
print is_coprime(36,12)
print is_coprime(18,29)
print is_coprime(60,15)
</lang>
{{out}}<pre>
false
true
false
true
false
</pre>
 
781

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.