**Hello to all the friends of the forum!**

And of course also a special greeting to the very few girls who wandering through these posts! (but those that are there are really good! ).

I'm experimenting to figure out if a number belongs to the family of

**prime numbers**. That's why the post is called

**"amazing prime"**!

In short, LiveCode brings me home, for free, (almost) all the prime numbers I want!

The problem is the speed ...

I found two scripts that tell me if a number is a prime number.

The first is this:

Code: Select all

```
on mouseUp
ask ""
put p(it) into field "a"
end mouseUp
function p n
if n is 1 then return false
repeat with i=2 to n-1
if n mod i is 0 then return false
end repeat
return true
end p
```

The second is this:

Code: Select all

```
on mouseUp
local tNum
put fld 2 into tNum
put "" into fld 1
put isPrime(tNum) into fld 1
end mouseUp
function isPrime pNum
if pNum <> 2 AND pNum mod 2 = 0 then
return false
end if
repeat with x = 3 to sqrt(pNum) step 2
if pNum mod x = 0 then
return false
end if
end repeat
return true
end isPrime
```

Let's take this test with this proven prime number:

**10456997**

Both scripts give the same result:

**true!**

**The second script is much faster than the first!**

Now, let's try a new number (this is also a proven prime number). It's a bit bigger!

**9007199254740781**

**Both scripts give the same result: false!**

**Why FALSE?**Using pen and paper in about two minutes I have tried that 9007199254740781 is a prime number !!! (I'm joking, obviously)

Actually I used this site which, in real time, with a script, (I believe in javascript.. or php?), immediately gave me the result!

https://primes.utm.edu/curios/includes/primetest.php

How is this possible?

Thanks for the help, your

**amazing help!**

Mariasole

>^..^<

Mariasole

>^..^<