Skip to content
Advertisement

Tag: primes

BigInteger.isProbablePrime seems much more certain than it says it is

I understand the certainty argument to mean: certainty – a measure of the uncertainty that the caller is willing to tolerate: if the call returns true the probability that this BigInteger is prime exceeds (1 – 1/2certainty) From my experiments, it seems to exceed it by quite a lot! The code below finds “probable primes” between 2 and 1 million

How do I approach this recursively in Java?

In this program I need to get input from the user that indicates the length of the numbers with this quality: The number should be prime and if you delete each digit from the right the number that is left should still be prime. i.e. 2399 is such a number. Because 2399 is prime, and also 239, and 23, and

Prime numbers – I need clarification on code implementation

This is the code I know: But is this ok if you’re looking for prime numbers: Output: And also is there much difference in time complexity? Answer Your code is incorrect. This code only works because you are taking the value of n as 30, for a greater number like 1000 this will produce an incorrect result. List arr =

Java: Find out if a number is prime recursively

I’m writing a function that returns true if a number is prime, and false otherwise Here is my current code: It works for a lot of test cases except numbers like “1000000007” where I get an Out of memory error. How could I tweak this code to be more efficient space-wise? Answer The first problem I see is that your

Prime number in java 8

I was trying to write a simple prime number program in Java 8. Below is the program. I wanted to reduce the code in isPrime() as well. Is there something that filters the elements from 2 to n/2, and then apply filter for n%i == 0 which would make isPrime irrelevant? Answer IntStream can be used to generate integer stream

Advertisement