By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,654 Members | 1,517 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,654 IT Pros & Developers. It's quick & easy.

How to find prime of Big integer number?

P: 54
I want to find all the prime number less then some given big integer number.

like

BigInteger n=new BigInteger(jTextField1.getText());
then all prime number less then n.

While I tried it was giving error the increment and comparison operator can not be applied to BigInt..

Expand|Select|Wrap|Line Numbers
  1. for (i=1;i<n; n.add(BigInteger.ONE)) // Error : -- and >= can not be applied to java.math.BigInteger
  2. {
  3.  
  4. int ctr=0;
  5. for(x =i; x>=1; x--) // Error : -- and >= can not be applied to java.math.BigInteger
  6. {
  7. if(i%x==0) //Error : % can not be applied to java.math.BigInteger
  8. {
  9. ctr = ctr + 1;
  10. }
  11. }
  12. if (ctr ==2)
  13. {
  14. System.out.print(" " + i);
  15. }
  16.  
  17. }
Any solution to this?
Feb 3 '13 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 1,043
Out of pure interest, i google for the answer ;)
it seems to be here: http://stackoverflow.com/questions/1...use-biginteger

There is a long way to go before you hit the jackpot:
http://www.reuters.com/article/2013/...9170UO20130208
Feb 9 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.