Thread: factorization issues

  1. #16
    Registered User
    Join Date
    Feb 2009
    Posts
    66
    Quote Originally Posted by tabstop View Post

    When you multiply all the factors together of n together, you will always get n^x for some x[0]. For instance, for 999 the power is four because there are four pairs of factors, each of which (obviously) multiplies to 999: 1 x 999, 3 x 333, 9 x 111, and 27 x 37. For 998, the pairs of factors are 1 x 998, 2 x 499, so you end up with 998^2, which is small enough to fit.

    [0]x will be an integer unless n is a perfect square, in which case it will be a half-integer.
    so other than the n== my code is fine? there isnt anything i can do about the 999 issue?

  2. #17
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    If you want the range and are willing to give up the accuracy, you could make the product a floating-point number rather than an integer.

  3. #18
    Registered User
    Join Date
    Dec 2008
    Posts
    15
    Hello i've not seen your code, but i think that it's not possible with integers at least (don't know if you can program a number type the bit-size you want). But, if we factorize 999, we get 999=3*3*3*27, so we get that every product combination of this four numbers we get a really high number. Imagine just (3)*(3*3)*(3*3*3)*(3*27)*(3*3*27)*(3*3*3*27). Imagine what would happen with a bigger number. Impossible for an integer to hold all this.

    EDIT: the result is 10460353203
    Last edited by kiknewbie; 02-01-2009 at 03:12 AM.

  4. #19
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by kiknewbie View Post
    Hello i've not seen your code, but i think that it's not possible with integers at least (don't know if you can program a number type the bit-size you want). But, if we factorize 999, we get 999=3*3*3*27, so we get that every product combination of this four numbers we get a really high number. Imagine just (3)*(3*3)*(3*3*3)*(3*27)*(3*3*27)*(3*3*3*27). Imagine what would happen with a bigger number. Impossible for an integer to hold all this.

    EDIT: the result is 10460353203
    He also uses 1 and 999 so the result is even bigger
    the actual product is calculated in code as

    1*3*9*27*37*111*333*999
    so result is 3868550625
    Last edited by vart; 02-01-2009 at 04:12 AM.
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #20
    Registered User
    Join Date
    Feb 2009
    Posts
    66
    Quote Originally Posted by tabstop View Post
    If you want the range and are willing to give up the accuracy, you could make the product a floating-point number rather than an integer.
    i almost changed it to a float but i didn't think it would change anything. how will the accuracy change?

  6. #21
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by ominub View Post
    i almost changed it to a float but i didn't think it would change anything. how will the accuracy change?
    You won't get all the digits; you'll just see 9.96006e+11 instead.

  7. #22
    Registered User
    Join Date
    Feb 2009
    Posts
    66
    okay, so i understand why it does that, but is there a solution? more specifically, is there a solution that a student in an introductory course should do?

    either way, id really like to know.

    thanks for the help

    edit:

    i made it a <float> and i still got a negative number.
    Last edited by ominub; 02-01-2009 at 03:20 PM.

  8. #23
    Registered User
    Join Date
    Feb 2009
    Posts
    66
    okay i figured it out. it does have to be a float, but i forgot to change the %d to a %f. rookie mistake.

    oh well... thank you for all your help. i learned a lot.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Better spacing issues
    By swgh in forum C++ Programming
    Replies: 2
    Last Post: 01-02-2008, 04:46 PM
  2. Bitmap scroll issues
    By Gerread in forum Windows Programming
    Replies: 4
    Last Post: 05-14-2007, 05:18 AM
  3. Major game issues
    By VOX in forum Game Programming
    Replies: 0
    Last Post: 01-18-2005, 08:40 AM
  4. Multi-platform support issues.
    By OOPboredom in forum C Programming
    Replies: 2
    Last Post: 04-27-2004, 06:41 PM
  5. hexdump issues
    By daluu in forum C Programming
    Replies: 2
    Last Post: 03-04-2003, 09:01 PM