In [ ]:
function sol3(tar::Int)
n :: Int, i :: Int, cur :: Int = tar,3,tar
while true
In [2]:
function odd_prime(n::Int)
for i = 3:2:isqrt(n)
if 0 == rem(n,i)
return false
end
end
return true
end
Out[2]:
In [24]:
function sol174(lim :: Int)
ctr :: Array{Int,1} = zeros(Int,lim)
res :: Int = 0
i :: Int = 1
while true
isqr :: Int = i*i
tmp :: Int = (i+2)^2-isqr
if tmp > lim
break
else
j :: Int = i+2
jsqr :: Int = j*j
jtmp :: Int = jsqr-isqr
while true
if jtmp > lim
break
else
ctr[jtmp] += 1
j += 2
jsqr = j*j
jtmp = jsqr-isqr
end
end
i += 1
end
end
for k = 4:4:lim
m :: Int = ctr[k]
if 1 <= m && m <= 10
res += 1
end
end
return res
end
Out[24]:
In [14]:
map(x -> x^2 - 16, 6:2:30)
Out[14]:
In [12]:
@time sol173(1000000)
Out[12]:
In [10]:
function sol173(lim :: Int)
res :: Int = 0
i :: Int = 1
while true
isqr :: Int = i*i
tmp :: Int = (i+2)^2-isqr
if tmp > lim
return res
else
j :: Int = i+2
jsqr :: Int = j*j
while true
if jsqr-isqr > lim
break
else
res += 1
j += 2
jsqr = j*j
end
end
i += 1
end
end
end
Out[10]: