Questions tagged [primality-test]

A primality test is an algorithm for determining whether an input number is prime.

A primality test is an algorithm for determining whether an input number is prime.

See https://en.wikipedia.org/wiki/Primality_test.

115 questions
-1
votes
1 answer

Miller-Rabin Primality Test Often Returns Composite for Prime Numbers

I have been trying to implement a Miller-Rabin primality test from scratch (only primitives and Strings) that works for 64 bit integers (longs). I've tried the Java and pseudocode from Wikipedia, as well as various other websites. So far, only very…
-1
votes
1 answer

Goldbach’s Conjecture in prolog

Goldbach’s Conjecture : Every positive even number greater than 2 is the sum of two prime numbers. Eg 28 (5,23 and 11,17) I want Prolog code to print below (all combinations) : ?- goldbach(28, L). Output : L = [5,23]; L = [11, 17]; I have a code…
KFC
  • 541
  • 1
  • 4
  • 17
-1
votes
5 answers

Program that checks if a number is prime number

Hello I have created this program to check if a number is a prime number. It works but for some reason says that 999 is a prime number. Where is my mistake. It would be great if someone explained. Thank You! Here is my program: number =…
user6029982
-1
votes
2 answers

Why is this elementary Prolog predicate not stopping execution?

I want to write a predicate that determines if a number is prime or not. I am doing this by a brute force O(sqrt(n)) algorithm: 1) If number is 2, return true and do not check any more predicates. 2) If the number is even, return false and do no…
Rob L
  • 3,073
  • 6
  • 31
  • 61
-2
votes
2 answers

How about big numbers? ( primality tests )

Is this a 'real' task, that can be written on any language ( C/C++, for example ) So, my task is 'generate' random number with length over 50 digits ( maximum = 200 )? Then, i must check this number on primality test. So, is this task 'real' and…
gaussblurinc
  • 3,642
  • 9
  • 35
  • 64
-2
votes
1 answer

Primality Test Comparison

I found a new primality test below which determines if 1000000007 is prime. How does its speed compare to other existing primality algorithms? Does it win the award for most "computationally worthless" primality test? Thanks. EDIT Was able to…
vengy
  • 1,548
  • 10
  • 18
-2
votes
3 answers

what is the fastest algorithm to identify prime numbers from an array of random numbers?

I have an array of random numbers and i have to return the prime numbers from that array. I am familiar with root(n) solution(n being that particular number not the size of the array). I can not apply sieve of Eratosthenes as it works with numbers…
-2
votes
3 answers

Primarily Test in O(1)

We know that all prime numbers are of the form 6k+-1. To check if n is a prime number, can't we just divide n by 6, take the floor of that, then check if adding or subtracting 1 equals n? That would check if a number is prime in constant time,…
-3
votes
2 answers

why the iteration is done by i+6 every time and why the condition is i*i<=n for this prime testing function?

https://www.geeksforgeeks.org/primality-test-set-1-introduction-and-school-method/ // A optimized school method based C++ program to check // if a number is prime #include using namespace std; bool isPrime(int n) { //…
-5
votes
2 answers

Prime number Logic, n/2 condition in a loop

The following code is for prime number. I want to know why we use i<=n/2 condition in the loop. C Program: #include int main() { int n, i, flag = 0; printf("Enter a positive integer: "); scanf("%d",&n); for(i=2; i<=n/2; ++i) { //…
Fusionist
  • 115
  • 2
  • 3
  • 8
1 2 3 4 5 6 7
8