Why is my BigInteger Program Not Producing Any Output?

  • Thread starter Thread starter muna580
  • Start date Start date
  • Tags Tags
    Remainder
AI Thread Summary
The discussion centers around a Java program designed to find the smallest positive integer x such that the expression x^2 + 3x + 5 is divisible by 121. The program uses BigInteger for calculations but fails to print any results upon execution. A key point raised is that BigInteger is unnecessary for this problem, as the values involved do not exceed the limits of standard integer types like int or long. Ultimately, it is concluded that there is no solution to the problem posed, indicating that no positive integer x satisfies the divisibility condition.
muna580
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:
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);
				return;
			}
		}
		
	}
}
 
Last edited by a moderator:
Technology news on Phys.org
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.
 
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?
 
Yes, there is no solution.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top