Results 1 to 5 of 5

Thread: Calculating all Factors

  1. #1

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Pretty simple i think, but how do I do it?

  2. #2
    Addicted Member Active's Avatar
    Join Date
    Jan 2001
    Location
    Lat: 13° 4' 46" N, Long: 80° 15' 20" E
    Posts
    209
    check this..

    Code:
    Private Function IsFactor(Num, ofNum) As Boolean
    'Checks If Num is A factor of ofNum
    If Not Num = 0 Then
     IsFactor = ofNum Mod Num
     IsFactor = Not IsFactor
    End If
    End Function
    
    Private Sub Command1_Click()
    For i = -10 To 10
     If IsFactor(i, 56) Then
       List1.AddItem i
     End If
    Next
    End Sub
    BTW an iteration loop is no means an effiecient way to do this.
    still it's logical for smaller ranges of numbers.
    If you can't beat your computer at chess, try kickboxing !!!
    [Download Tag Editing Tools.]

  3. #3

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Oh, OK...

    I am working on some other code for factors and trinomials, so I will hopefully post that here

  4. #4
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    An approach.

    I assume that you are talking about finding all prime factors of a given number. For example: 29, 17, 3, & 3 are the factors of 4437.

    An approach would be to start by using an array of known primes: 2, 3, 5, 7, 11, 13, 17 . . . .

    Find all the primes you can via the array. If there are more primes to be found, try every odd number after the last prime in the array.

    For a VB program, you could have the user put a number into a Text Box, which you would immediatley put into a List Box. The general approach would be to work with the number put into the List Box, replacing it with two factors. For the above example, the List Box would contain the following after each cycle of the program.
    • 4437
    • 3, 1479
    • 3, 3, 439
    • 3, 3, 17, 29
    If you find no primes, the original number is the sole contents of the List Box.

    Note the following.
    • You you never need try a factor greater than the square root of the number you are working with. When you get past the square root of the number, you are finished. This is how you know when to stop trying for more factors.
    • Once you tried a number as a factor, you need not try that factor nor any smaller factor. This provides a rule for avoiding extra work.
    I used the above general idea to write a factoring program for my HP48GX calculator. Instead of the List Box, I used the LIFO Stack provided by the calculator.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  5. #5

    Thread Starter
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    mmmmkay, thanks, still a bit hazy about the idea, anybody else written a program for this?

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