Results 1 to 4 of 4

Thread: [RESOLVED] Math question: Finding divisors.

  1. #1

    Thread Starter
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    Resolved [RESOLVED] Math question: Finding divisors.

    Is there an efficient way to find all the divisors of a number that leave no remainder? And by efficient, I don't mean dividing a number by every other number to see if the remainder is zero.
    Prefix has no suffix, but suffix has a prefix.

  2. #2
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Math question: Finding divisors.

    I could be wrong but I don't think there are easy solutions for this, not for big numbers anyway.

    If you had a list of all prime numbers up to N, then you could use that list to determine the factors of numbers up to N², this would be more efficient than testing with every number.

    You could write a variant of the Sieve of Eratosthenes where rather than just marking composites you log the prime factors.

    Check out...
    Rational sieve
    Special number field sieve
    General number field sieve

    The latter two made my little brain hurt
    W o t . S i g

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: Math question: Finding divisors.

    If there was a truly easy method to find this other than a brute force approach, then modern computer security would become garbage, since it is based on the very difficulty of factoring large numbers even for powerful computers.
    My usual boring signature: Nothing

  4. #4
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: [RESOLVED] Math question: Finding divisors.

    Ehehe... no. But you can loop through them, too!
    Code:
    Dim factors As New List(Of Integer)
    If numbertofactor = 0 Then Exit Sub
    For i As Integer = 0 To (numbertofactor \ 2) + 1
         If (numbertofactor Mod i) = 0 Then factors.Add(i)
    Next

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width