I am working on a factorisation problem and for small numbers it is working well. I’ve been able to calculate the factors (getting the answers from Wolfram Alpha) for small numbers, like the one on the Wikipedia page (5959).
Along with the Wikipedia page I have been following this guide. Once again, as my Math knowledge is pretty poor I cannot follow what I need to do next.
EDIT: It finally works! I’ll post the working code up here once I’ve got it fully working so that others in my predicament can learn from it.
In your loop:
what is the purpose of the following instruction?
I think that in order to check that
b2is a square, you should instead try to compute the square root (the above instruction is just one step of the canonical algorithm to compute square roots), with the method you already have:The same observation applies to this code:
EDIT. The problem is that your
sqrt()method needs anisSqrt()that checks whetherrootis an approximate root ofn, whereas the loop infermat()needs an exact check.I append some code that seems to pass your last test: