
-----------------------------------
cool dude
Mon Jun 19, 2006 7:37 pm

too big for BigInteger
-----------------------------------
i'm trying to make a program to solve a math problem which is 


What is the largest prime factor of the number 317584931803?



the problem i'm having is that even BigInteger says its too big of a number so is there any alternatives?

-----------------------------------
Martin
Mon Jun 19, 2006 8:43 pm


-----------------------------------
I think there's something wrong with your algorithm, or how you're using BigInt. You could just use a long long though, the number is small enough.

-----------------------------------
cool dude
Mon Jun 19, 2006 9:07 pm


-----------------------------------
did u actually try it? 

BigInteger num = BigInteger.valueOf(317584931803);

it cleary says integer number too large. long long :? wats that? or is it just long?

-----------------------------------
Martin
Mon Jun 19, 2006 10:00 pm


-----------------------------------
A long long is a 64 bit integer. A long is just an int.

But your problem is that you're declaring BigInt wrong. You're passing it 317584931803 as an integer, which is too big for an integer. Pass it as a string instead and you'll be fine.

-----------------------------------
cool dude
Tue Jun 20, 2006 5:33 pm


-----------------------------------
thanks using it as a string works. another question. wat syntax do u use with BigInteger to check if it is equal to something or greater/smaller than something?

-----------------------------------
rizzix
Tue Jun 20, 2006 6:21 pm


-----------------------------------
If you read the docs you'll notice that BigInteger implements Comparable.

Thus you can easily compare two BigIntegers.

For more info, look up Comparable.

-----------------------------------
cool dude
Wed Jun 21, 2006 9:20 am


-----------------------------------
i searched on the internet but it doesn't show anything relevant. :? 

this is the line of code i need to compareTo

if (num.remainder (BigInteger.valueOf(i) == 0))

obviously i can't use the == operator because it doesn't work with BigInteger.

-----------------------------------
[Gandalf]
Wed Jun 21, 2006 9:41 am


-----------------------------------
You searched the internet, yet you didn't check the Java documentation? :roll:  Hey look, it's also the first thing that Google pops up: [url=http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Comparable.html]here.

-----------------------------------
cool dude
Wed Jun 21, 2006 3:11 pm


-----------------------------------
k thanks i figured it out. the only problem i'm getting is that i'm not getting any output. 


import java.math.*;
public class Problem3{
	public static void main(String[] args){
		BigInteger num = new BigInteger("317584931803");
		for(int i = 1; i 