How can I write a code showing that two numbers are prime between them?

PRIME BETWEEN: If two positive integers do not have 1 common divisor, these numbers are prime between them.(except one)

I’m not understanding what you mean by

Could you give an example

For example, 5 and 3 are prime because they both have no common divisor other than 1
Example 8 and 9
8 s common divisors are ; 1 , 2 , 4 , 8
9 s common divisors are ; 1 , 3 , 9
So they are prime between because they both have no common divisors other than 1.

You could take two numbers, factorize them, (get a list of factors), and then compare each value in list one, two each value in list two. If there are no matches, they are prime between. I will try to figure out how this would be done and write a simple script.

1 Like

Prime divisors are 1 and the number. Regarding yesterday’s question, what is wrong

I guess you would have to get the factors of the numbers compile them in a list and compare them?

I didn’t say prime numbers, I said numbers between them

Making a table with the numbers that the original one can be divided; e.g. no 2.5 numbers


I am confused confusion

An algorithm selects two random numbers and finds their common divisors, the numbers that are common to both, if not found, then writes prime between them.

Wait so is 6 and 3 prime between them or not?
3 is a factor of 6? I am not sure what you are trying to find.

they are not prime between them because they both have 3
that is, they both can be divided by 3 and they are not because it is a multiple of 3.

So you mean…

9 and 27;
their common divisors are:
3,9

You want to find common divisors between two numbers??

yes but also a code that finds if they prime between.

Get a random number and then do some calculations as I said yesterday and above, store them in a table, do the same for the second number, loop in the table and if you find the same number, list it.

I compiled a functino like this which should do as expected

function arePrimeBetween(num1, num2)
	local factors1 = {}
	local factors2 = {}
	
	for i = 1, math.max(num1, num2) do
		if (num1 % i) == 0 then
			table.insert(factors1, i)
		end
		if (num2 % i) == 0 then
			table.insert(factors2, i)
		end
	end
	
	local foundSame = false
	
	for _,num in pairs(factors1) do
		if table.find(factors2, num) and num ~= 1 then
			foundSame = true
			break
		end
	end
	
	return not foundSame
end

Gets the factors by checking by going through a loop from 1 tothe largest number, checks if the number is a factor by dividing it from both numbers and seeing if the remainder is 0 and adding it to respective tables

Then loop through 1 of the tables and seeing if that number is found in the other, if it is, stop the loop and return the inverse of foundSame

So if it finds no duplicates, it returns not false so true and vice versa

Be warned it will crash your roblox if you give it a large number, you can probably fix it a bit by checking by a percentage of the largest number in the f or loop and then adding itself in the tables manually

You can tweak it around to get the common divisors as well, I cna’t right now since I crashed my roblox trying to use a large number

There’s probably a better way to do it

2 Likes

In that case you could just try dividing by all the prime numbers and see if they fit. e.g.
51, 36
So you would simple do
51/2
36/2
then
51/3
36/3
and keep dividing by the prime numbers.
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53.
Then you should stop when the biggest prime number is greater than half that of the smallest number.
If you use MOD you can check whether or not they leave a reminder.
If both numbers do not leave a remainderthen bingo you have it
if they do leave remainders then they do not have a common factor.

1 is prime between all numbers and try it.
For example, write 5 on Num1 and 1 on Num2 and see what will happen.

I used this before in s script to print out the greatest common divisor. You might want to look into it.

local a = 20, b = 5, GCD = 0;
while  b  ~=  0 do
    GCD = b;
    b = a % b;
    a = GCD;
end
print(GCD);

You could simply check whether or not the GCD is 1 or not.