Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

BigInteger Remainder Help

  1. Oct 27, 2006 #1
    Okay, I made this program in order to solve this question

    What is the smallest positive integer x such that x^2 + 3x + 5 is divisible by 121?

    The program complies perfectly. But when I execute it, it don't print out any answer.

    Code (Text):
    import java.math.BigInteger;

    public class Number37
        public static void main (String[] args)
            BigInteger divider = BigInteger.valueOf(121);
            BigInteger ZERO = BigInteger.ZERO;
            BigInteger THREE = BigInteger.valueOf(3);
            BigInteger FIVE = BigInteger.valueOf(5);

            BigInteger n = BigInteger.valueOf(0);
            BigInteger val1 = n.pow(2);
            BigInteger val2 = n.multiply(THREE);

            for (long i = 0; i < Long.MAX_VALUE; i++)
                n = BigInteger.valueOf(i);
                BigInteger value = (val1.add(val2)).add(FIVE);
                if(value.remainder(divider) == ZERO)
                    System.out.println("N is equal to: "  + n);
    Last edited by a moderator: Oct 27, 2006
  2. jcsd
  3. Oct 28, 2006 #2
    You don't have to use BigInteger here, you use BigInteger and BigDecimal when
    o) need a integer/decimal that is larger than +/- 2^61/2
    o) need arbitrary precision that is a double/long can give you only up to 15 digits of precision more or less.

    here I think it is safe to use int or long.
  4. Oct 28, 2006 #3
    Well, even though I don't need the BigInteger here, I still used it and programmed it correctly. But since its not giving me an answer, would you say there is NO SOLUTION to teh questio nI am trying to program?
  5. Oct 28, 2006 #4


    User Avatar
    Science Advisor

    Yes, there is no solution.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook