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
0
votes
1 answer

Why is one of these prime number generators faster than the other?

Recently interested in simple primality tests. I have the following two functions that return a list of all primes up to the given input. The first I made, the other is based off wikipedia's pseudocode for primality tests. I then slightly altered…
dieggsy
  • 362
  • 1
  • 4
  • 13
0
votes
1 answer

Miller-Rabin primality test gives wrong answer

I'm trying to make a RSA algorithm. For that i need rabin-miller+witness+modular exponentiation(at least I'm required to use that). The problem comes when i generate random numbers to check with rabin miller if they are primes, and the result is…
Lolo
  • 7
  • 1
  • 7
0
votes
1 answer

Check if a number is prime without sieve

So i need to solve a problem that finds the n-th number that verifies the following: it is the sum of two consecutive primes and it gives an integer square root. My problem is that the sieve of eratosthenes uses too much memory and the naive…
Andy
  • 155
  • 1
  • 13
0
votes
1 answer

Prime number check

I'm having some issues with my prime number checker in F#. It doesn't seem to give the right results so I'm guessing I've screwed up the logic somewhere but I can't figure out where. The implementation is a simple brute forcing one so the logic…
0
votes
1 answer

How to test primality in Verilog?

I have the Verilog code shown below, and if I try to compile it I get an error message. The point is that I'm trying to manipulate an input, which as long as I know cannot be done in Verilog. The point is that I need check the following condition in…
user1726549
0
votes
1 answer

Miller-Rabin code - can't find any mistakes?

I used some code taken from Rosetta Code. I renamed a few things but I didn't really change anything. import random def is_probable_prime(n, num_trials = 5): assert n >= 2 if n == 2: return True if n % 2 == 0: return…
qwr
  • 9,525
  • 5
  • 58
  • 102
0
votes
0 answers

Dual Variable Solutions from Primal in Cplex

I am coding cplex concert technology in C++. When I solve primal problem (with primal simplex, dual simplex or interior point, method is not important), can I extract solution values, such as extreme ray values of dual variables if dual problem is…
user1450005
  • 53
  • 2
  • 9
0
votes
2 answers

Issue with longs dividing and then modding correctly in Python

I'm trying to implement a primality test for an RSA implementation I'm writing as an excercise. I'm mainly using Rabin-Miller, but I do have a Sieve of Eratosthenes formulating a list of all the primes under a thousand to use for a quick test to…
0
votes
2 answers

Determining whether a number is prime or not

I know it's been discussed many times; I've read it, but somehow I can't get it. I want to write a program that determines if the entered number is prime or not. One of the implementations I found somewhere on the Internet: from math import * def…
nutship
  • 4,624
  • 13
  • 47
  • 64
0
votes
1 answer

Primality proof algorithms for extremely large integers of no specific form

I am looking for an algorithm that would make it possible to prove any large number for primality. By large number, I mean numbers with at least 100,000,000 decimal digits in them and which cannot be expressed with simple formulas like Mersenne…
Adam
  • 3,668
  • 6
  • 30
  • 55
0
votes
3 answers

Suitable Language for RSA implementation

I want to implement an RSA cryptosystem algorithm for a university project and I' m trying to decide which programming language to use. I am very familiar with C so it would be a convenient choice. However, the algorithm will have to deal with very…
CherryBrandy
  • 55
  • 1
  • 6
-1
votes
3 answers

in Primality Test ,i do not understand why we increase i by 6 (i=i+6) ? and the if statment conditions in the for loop block?

i need some help please !! this is the code i founded in data-strucure book i understand that t all primes are of the form 6k ± 1, with the exception of 2 and 3 where k is some integer. the problem is in the for loop why we add 6 to i (i+6) and…
-1
votes
1 answer

How do I check the primality of a very large BigInt fast?

I am generating a large BigInt and need to test whether it is a prime number or not. However, this simple algorithm takes way to long. bool _isProbablePrime(BigInt n) { var _isPrime = true; for (var i = BigInt.from(2); i < (n); i = i +…
MindStudio
  • 706
  • 1
  • 4
  • 13
-1
votes
3 answers

Primality Test algorithm fails

I created a simple primality test algorithm, but it fails for numbers like 15. Why? number = int(input("Test if Prime: ")) print ("Is " + str(number) + " Prime?: ") for i in range (2, number): if number % i == 0: print ("No") break …
DarkRunner
  • 449
  • 4
  • 15
-1
votes
1 answer

Is it worth memoising a primality test?

I have another backtracking challenge, in which I have to get all possible combinations of prime numbers that add up to a certain number. I have finished the task using the general use algorithm from Wikipedia, but for the number 100, it took more…
Mark Gardner
  • 442
  • 1
  • 6
  • 18