Why is my BigInteger Program Not Producing Any Output?

  • Thread starter Thread starter muna580
  • Start date Start date
  • Tags Tags
    Remainder
Click For Summary

Discussion Overview

The discussion revolves 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 focus is on debugging the program, which compiles but does not produce any output when executed.

Discussion Character

  • Technical explanation, Debate/contested, Homework-related

Main Points Raised

  • One participant describes their program and notes that it compiles without errors but fails to print any output.
  • Another participant suggests that using BigInteger may be unnecessary for this problem and proposes that int or long could suffice.
  • A participant questions whether the lack of output implies that there is no solution to the problem posed.
  • Another participant asserts that there is no solution to the problem.

Areas of Agreement / Disagreement

There is disagreement regarding the necessity of using BigInteger, and while one participant questions the existence of a solution, another claims definitively that there is no solution.

Contextual Notes

The discussion does not clarify the assumptions regarding the problem's constraints or the behavior of the program, particularly in relation to the loop and the conditions for output.

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 the questio nI am trying to program?
 
Yes, there is no solution.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K
Replies
2
Views
3K
Replies
1
Views
3K
  • · Replies 25 ·
Replies
25
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
3
Views
3K