Pyhton data's structural size and loop efficiency

Click For Summary

Discussion Overview

The discussion revolves around the efficiency of algorithms for finding the largest prime factor of a composite number, particularly focusing on the performance issues encountered when the input number exceeds certain limits. Participants explore various methods for reducing loop time and improving factorization efficiency.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant describes a standard method for finding prime factors that involves looping through natural numbers, but notes that this approach becomes inefficient for large inputs.
  • Another participant expresses confusion regarding the term "composite" and requests clarification on the time reduction aspect, suggesting the inclusion of code examples or alternative programming languages like C or Fortran.
  • A participant shares a link to a Wikipedia page on integer factorization, implying that it may contain useful information for the discussion.
  • Another participant reiterates the need for time-efficient methods for factorization and mentions that there are relevant wiki pages available.
  • One participant proposes a multi-step algorithm that includes generating prime numbers efficiently using methods like the Sieve of Eratosthenes, checking for prime factors, and dividing the input number to reduce its size for faster subsequent tests.

Areas of Agreement / Disagreement

Participants express varying levels of understanding and agreement on the problem and potential solutions. There is no consensus on a specific method or approach, and multiple competing views on how to achieve time efficiency remain present.

Contextual Notes

Some participants may have differing interpretations of key terms, and there is uncertainty regarding the specific implementation details of proposed algorithms. The discussion also reflects a lack of clarity on the definitions and assumptions surrounding composite numbers and factorization methods.

Kartik.
Messages
55
Reaction score
1
While programming to find the largest prime factor for a composite number i came across a problem that if the number taken as input exceeds a certain limit, the loop time turns out to be a very long one and some times even resembling the time taken by an infinite loop.The method used for finding the prime factors is a standard one in which we loop through natural number until the input equals the loop counter; finding its factors and then checking for it to be prime or not ;through another function by a similar method using a counter variable.? Alternatives for drastic time reduction ?
 
Technology news on Phys.org
I lost you at "composite".

time reduction of what? you going to show us some code?

how about wrapping some 'C' or 'Fortran' code?
 
gsal said:
I lost you at "composite".

time reduction of what? you going to show us some code?

how about wrapping some 'C' or 'Fortran' code?

I wrote about the time it takes to loop through natural number during program execution and wanted any time-efficient method for factorization.(They have wiki pages for that too :P)
 
I guess the simplest algorithm would be something like this:

(1) find an efficient way to generate all prime numbers up to the square root of the input. Something like Sieve. Or use a pre-calculated table if you know what the largest input number is.

(2) start checking from the smallest prime=2 up.

(3) as soon as you find a prime factor, divide the input number by this factor. Do this several times if the factor occurs in a higher power than 1. Dividing will make the test number smaller and subsequent tests faster (assuming your input is larger than standard 32-bit integers).

(4) repeat with the next largest prime, up to the largest prime smaller than the square root.

(5) if you don't find a prime factor smaller than the square root, then the input number is a prime.
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
Replies
1
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 31 ·
2
Replies
31
Views
5K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 12 ·
Replies
12
Views
5K