I’m not a mathematician but I love algorithms and as many before me I’ve fallen in love with the prime numbers. I thought of an algorithm for proving a number is prime but I cannot access its complexity. I only know for any n in the worst-case scenario it makes some $\sqrt{n}$ checks (I guess, for 25 takes 3 iterations, for 11 takes 2, if it's relevant). The algorithm goes as follows:

1) let $ h = 2, w = n/h$ (truncated result), $r$ = $ n$ mod h (remainder)

2) if $r = 0\implies$ it’s not a prime number (we’re done with the check), else let h = h + 1, $d = w - r$, $p = d/h$ and $pr$ = $d$ mod h

3) if $pr = 0\implies$ not a prime number, r = h - pr, h = h + 1, w = w – (p + 1)
we go to 2) and repeat until r = 0 or h = $\sqrt{n}$ + 1
If we reach h = $\sqrt{n}$ + 1 and still have r > 0, it means the number is prime.

I’m sorry for the lame question and the probably invalid mathematical notation used. I’m neither a native speaker nor mathematician but I’ll be happy to receive some feedback on the validity/complexity of the algorithm above. Thank you in advance for your time!

Example:

n = 25

h = 2

w = n/h = 12

r = n mod h = 1

r > 0 => h = h + 1 = 3

d = w – r =12 – 1 = 11

p = d/h = 11/3 = 3

pr = d mod h = 2

pr > 0 => r = h – pr = 3 – 2 = 1

h = h + 1 = 3 +1 = 4

w = w – (p + 1) = 12 – (3 + 1) = 8

step 2)

r > 0 => h = h + 1 = 4 + 1 = 5

d = w – r = 8 – 3 = 7

p = d/h = 7/4 = 1

pr = d mod h = 3

pr > 0 => r = h – pr = 4 – 3 = 1

h = h + 1 = 4 + 1 = 5

w = w – (p + 1) = 8 – (1 + 1) = 6

step 2)

r > 0 => h = h + 1 = 5 + 1 = 6

d = w – r = 6 – 1 = 5

p = d/h = 5/5

pr = d mod h = 5 mod 5 = 0

pr = 0 => not a prime