Skip to main content
Use real fractions and square root characters in text
Source Link
Toby Speight
  • 88.3k
  • 14
  • 104
  • 327

For starters, you only need to check odd numbers (potential primes) below sqrt(X)√X.

If A * B == X, then:

  • Either A == B and X is a perfect square, so the largest prime dividing A is the largest prime factor,
  • Or one of A and B is less than the other, and thus less than the sqrt(X)√X.

Without loss of generality, say A is less than B. Then B would be greater than the sqrt(X)√X, but the largest prime factor in A or B would be the largest prime factor of X.

So, you can start testing B, and just like X, you only need to test numbersonly numbers less than the sqrt(B)√B, and when testing A only those less than the sqrt(A)√A.

You can keep a list of numbers that divide X, I would always try to find a factor of the largest number that divides X:

  • If it is prime, it is the largest prime factor.
  • But if you do find a factor of the largest, get rid of it and replace it with its two factors. Then once again, find the largest factor and prove it is prime or composite.

I would also start your loop for finding a factor "from the bottom," not from the top, to play the odds.

1/3 of all numbers are divisible by 3, 1/5 divisible by 5, etc. You can divide by 2 as many times as possible before beginning. Then keep track of the largest odd number you have tried (prime or not, that will include all primes), so once they fail, you don't need to try them again.

For starters, you only need to check odd numbers (potential primes) below sqrt(X).

If A * B == X, then:

  • Either A == B and X is a perfect square, so the largest prime dividing A is the largest prime factor,
  • Or one of A and B is less than the other, and thus less than the sqrt(X).

Without loss of generality, say A is less than B. Then B would be greater than the sqrt(X), but the largest prime factor in A or B would be the largest prime factor of X.

So, you can start testing B, and just like X, you only need to test numbers less than the sqrt(B), and when testing A those less than the sqrt(A).

You can keep a list of numbers that divide X, I would always try to find a factor of the largest number that divides X:

  • If it is prime, it is the largest prime factor.
  • But if you do find a factor of the largest, get rid of it and replace it with its two factors. Then once again, find the largest factor and prove it is prime or composite.

I would also start your loop for finding a factor "from the bottom," not from the top, to play the odds.

1/3 of all numbers are divisible by 3, 1/5 divisible by 5, etc. You can divide by 2 as many times as possible before beginning. Then keep track of the largest odd number you have tried (prime or not, that will include all primes), so once they fail, you don't need to try them again.

For starters, you only need to check odd numbers (potential primes) below √X.

If A * B == X, then:

  • Either A == B and X is a perfect square, so the largest prime dividing A is the largest prime factor,
  • Or one of A and B is less than the other, and thus less than √X.

Without loss of generality, say A is less than B. Then B would be greater than √X, but the largest prime factor in A or B would be the largest prime factor of X.

So, you can start testing B, and just like X, you need to test only numbers less than √B, and when testing A only those less than √A.

You can keep a list of numbers that divide X, I would always try to find a factor of the largest number that divides X:

  • If it is prime, it is the largest prime factor.
  • But if you do find a factor of the largest, get rid of it and replace it with its two factors. Then once again, find the largest factor and prove it is prime or composite.

I would also start your loop for finding a factor "from the bottom," not from the top, to play the odds.

of all numbers are divisible by 3, divisible by 5, etc. You can divide by 2 as many times as possible before beginning. Then keep track of the largest odd number you have tried (prime or not, that will include all primes), so once they fail, you don't need to try them again.

For starters, you only need to check odd numbers (potential primes) below sqrt(X)sqrt(X).

If A*B=XA * B == X, then either A=B and X is a perfect square, so the largest prime dividing A is the largest prime factor.:

  • Either A == B and X is a perfect square, so the largest prime dividing A is the largest prime factor,
  • Or one of A and B is less than the other, and thus less than the sqrt(X).

OR, one of A and B is less than the other, and thus less than the sqrt(X). WithoutWithout loss of generality, say AA is less than BB. Then BB would be greater than the sqrt(X)sqrt(X), but the largest prime factor in AA or BB would be the largest prime factor of XX.

So, you can start testing BB, and just like XX, you only need to test numbers less than the sqrt(B)sqrt(B), and when testing AA those less than the sqrt(A)sqrt(A).

You can keep a list of numbers that divide XX, I would always try to find a factor of the largest number that divides XX: If it is prime, it is the largest prime factor. But if you do find a factor of the largest, get rid of it and replace it with its two factors. Then once again, find the largest factor and prove it is prime or composite.

  • If it is prime, it is the largest prime factor.
  • But if you do find a factor of the largest, get rid of it and replace it with its two factors. Then once again, find the largest factor and prove it is prime or composite.

I would also start your loop for finding a factor "from the bottom"bottom," not from the top, to play the odds.

1/3 of all numbers are divisible by 3, 1/5 divisible by 5, etc. You can divide by 2 as many times as possible before beginning. Then keep track of the largest odd number you have tried (prime or not, that will include all primes), so once they fail, you don't need to try them again.

For starters, you only need to check odd numbers (potential primes) below sqrt(X).

If A*B=X, then either A=B and X is a perfect square, so the largest prime dividing A is the largest prime factor.

OR, one of A and B is less than the other, and thus less than the sqrt(X). Without loss of generality, say A is less than B. Then B would be greater than the sqrt(X), but the largest prime factor in A or B would be the largest prime factor of X.

So, you can start testing B, and just like X, you only need to test numbers less than the sqrt(B), and when testing A those less than the sqrt(A).

You can keep a list of numbers that divide X, I would always try to find a factor of the largest number that divides X: If it is prime, it is the largest prime factor. But if you do find a factor of the largest, get rid of it and replace it with its two factors. Then once again, find the largest factor and prove it is prime or composite.

I would also start your loop for finding a factor "from the bottom", not from the top, to play the odds.

1/3 of all numbers are divisible by 3, 1/5 divisible by 5, etc. You can divide by 2 as many times as possible before beginning. Then keep track of the largest odd number you have tried (prime or not, that will include all primes), so once they fail, you don't need to try them again.

For starters, you only need to check odd numbers (potential primes) below sqrt(X).

If A * B == X, then:

  • Either A == B and X is a perfect square, so the largest prime dividing A is the largest prime factor,
  • Or one of A and B is less than the other, and thus less than the sqrt(X).

Without loss of generality, say A is less than B. Then B would be greater than the sqrt(X), but the largest prime factor in A or B would be the largest prime factor of X.

So, you can start testing B, and just like X, you only need to test numbers less than the sqrt(B), and when testing A those less than the sqrt(A).

You can keep a list of numbers that divide X, I would always try to find a factor of the largest number that divides X:

  • If it is prime, it is the largest prime factor.
  • But if you do find a factor of the largest, get rid of it and replace it with its two factors. Then once again, find the largest factor and prove it is prime or composite.

I would also start your loop for finding a factor "from the bottom," not from the top, to play the odds.

1/3 of all numbers are divisible by 3, 1/5 divisible by 5, etc. You can divide by 2 as many times as possible before beginning. Then keep track of the largest odd number you have tried (prime or not, that will include all primes), so once they fail, you don't need to try them again.

Source Link
Amadeus
  • 141
  • 1

For starters, you only need to check odd numbers (potential primes) below sqrt(X).

If A*B=X, then either A=B and X is a perfect square, so the largest prime dividing A is the largest prime factor.

OR, one of A and B is less than the other, and thus less than the sqrt(X). Without loss of generality, say A is less than B. Then B would be greater than the sqrt(X), but the largest prime factor in A or B would be the largest prime factor of X.

So, you can start testing B, and just like X, you only need to test numbers less than the sqrt(B), and when testing A those less than the sqrt(A).

You can keep a list of numbers that divide X, I would always try to find a factor of the largest number that divides X: If it is prime, it is the largest prime factor. But if you do find a factor of the largest, get rid of it and replace it with its two factors. Then once again, find the largest factor and prove it is prime or composite.

I would also start your loop for finding a factor "from the bottom", not from the top, to play the odds.

1/3 of all numbers are divisible by 3, 1/5 divisible by 5, etc. You can divide by 2 as many times as possible before beginning. Then keep track of the largest odd number you have tried (prime or not, that will include all primes), so once they fail, you don't need to try them again.