Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: BigInteger.isPrime

  1. #1
    Member
    Join Date
    Feb 2013
    Posts
    78
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default BigInteger.isPrime

    Hey guys. So I am trying to just get a method that can tell me if a BigInteger is FOR SURE prime, and I have had little luck. The best method that I have found online says 25 is prime... anyone know a good way to do it?

  2. #2
    Member angstrem's Avatar
    Join Date
    Mar 2013
    Location
    Ukraine
    Posts
    200
    My Mood
    Happy
    Thanks
    9
    Thanked 31 Times in 29 Posts

    Default Re: BigInteger.isPrime

    You see, the computation of primes always was pretty difficult problem. You have to do lot's of computations to discover whether a number is a prime or not. The most straightforward algorithm is to check whether a number can be divided by some number less than it. And it appears to be pretty efficient, but not in the context of prime number generator.

  3. #3
    Member
    Join Date
    Sep 2012
    Posts
    128
    Thanks
    1
    Thanked 14 Times in 14 Posts

    Default Re: BigInteger.isPrime

    For large numbers, you would have to look deeper and study things like the Sieves of Eratosthenes, Euler etc ... (Sieve of Eratosthenes - Wikipedia, the free encyclopedia)

Similar Threads

  1. Euclid Calculator GCD and LCM using BigInteger
    By Exiled in forum What's Wrong With My Code?
    Replies: 7
    Last Post: November 18th, 2012, 11:00 PM
  2. [SOLVED] isPrime Boolean Method returns true for squares of primes
    By Staticity in forum What's Wrong With My Code?
    Replies: 0
    Last Post: September 29th, 2011, 11:46 PM