Jump to content

Sum of square and cube digits of an integer are primes: Difference between revisions

Line 716:
16 17 25 28 34 37 47 52 64
</pre>
 
=={{header|Yabasic}}==
{{trans|Ring}}
<lang Yabasic>// Rosetta Code problem: http://rosettacode.org/wiki/Sum_of_square_and_cube_digits_of_an_integer_are_primes
// by Galileo, 04/2022
 
sub isPrime(n)
local d
d = 5
if n < 2 return false
if not mod(n, 2) return n = 2
if not mod(n, 3) return n = 3
while d*d <= n
if not mod(n, d) return false
d = d + 2
if not mod(n, d) return false
d = d + 4
wend
return true
end sub
limit = 100
for n = 1 to limit
sums = 0
sumc = 0
sps$ = str$(n^2)
spc$ = str$(n^3)
for m = 1 to len(sps$)
sums = sums + val(mid$(sps$, m, 1))
next
for p = 1 to len(spc$)
sumc = sumc + val(mid$(spc$, p, 1))
next
if isPrime(sums) and isPrime(sumc) then
print n, " ";
endif
next
print</lang>
{{out}}
<pre>16 17 25 28 34 37 47 52 64
---Program done, press RETURN---</pre>
672

edits

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