
| Current Path : /var/www/web-klick.de/dsh/50_dev2017/1310__algorithms/Julia/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/web-klick.de/dsh/50_dev2017/1310__algorithms/Julia/euler.jl |
using Debug
function issquare6(n::Integer)
n&2 == 0 || return false
rt = ifloor(sqrt(n)+0.1)
return rt*rt == n
end
function fast_is_square(i::Integer)
if ((1<<0 | 1<<1 | 1<<4 | 1 <> (i & 0xF) & 1))
t = ifloor(sqrt(i) + 0.5)
return t * t == i
end
return false
end
function euler141(B)
# d > q > r, q = r x/y, d = r x^2/y^2, take r = b y^2
# n = d^3/r + r = x^3/y^3 r^2 + r = b^2 x^3 y + b y^2, x >y, gcd(x,y) = 1
s = 0
x = 2
while true
xxx = x * x * x
xxx >= B && break # done, too big even for b == y ==1
for y = 1:(x-1)
gcd(x,y) > 1 && continue # try next y
yy = y * y
n = xxx * y + yy
n > B && break # too big, even for b == 1, try next x
v = 1
while n <= B
#if issquare6(n)
if fast_is_square(n)
s += n
#r = v*yy
#q = v*x*y
#d = v*x*x
#println("$n sum $s q $q d $d r $r x $x y $y")
end
v += 1
n = xxx * y * v*v + yy*v
end
end
x += 1
end
return s
end
#@time println(euler141(10^12))
function is_square(n)
root = sqrt(n)
return root*root == n
end
@debug function euler142()
result = 0
found = false
i = 4
while !found
println("while loop ", i)
@bp
randn(3,3)
a = i * i
for j = 3:(i-1)
c = j * j
f = a - c
println("first loop ", c, " ", f)
#(f <= 0 || !is_square(f)) && continue
if(f <= 0 || !is_square(f))
continue
end
kstart = (j&1==0) ? 1 : 2
for k = kstart:2:(j-1)
println("second loop")
d = k * k
e = a - d
b = c - e
(b <= 0 || e <= 0 || !is_square(b) || !is_square(e)) && continue
#if(b <= 0 || e <= 0 || !is_square(b) || !is_square(e))
# continue
#end
x = int((d + c) / 2)
y = int((e + f) / 2)
z = int((c - d) / 2)
result = x + y + z
#println(result)
found = true
end
end
i += 1
end
return result
end