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

Using nested for loops to generate primes

I created a primality test algorithm, but it doesn't work. In essence, these are the steps my program takes: Ask the user for a lower and upper bound in which to look for primes An array, primes, will store my primes A nested for loop; the first…
DarkRunner
  • 449
  • 4
  • 15
0
votes
1 answer

How to make primality test accept large numbers

I have a code for primality test that accepts integers up to 10 digits, but I want to extend this expansively so that the code accepts more than 200 digits. What should I switch in the code? import java.util.*; import java.math.*; class…
Ryuk
  • 37
  • 1
  • 4
0
votes
3 answers

Primality test using logical or relational operators on a 3-bit number

I am looking forward to check if a 3 bits number is prime using both logical and relational operators.The number is represented using 3 variables with bits 7-1 set to 0 and only the bit on position 0 being the actual data. Suppose we have: unsigned…
0
votes
1 answer

Brute Force primality check for 16 bit long integer

How can i use the brute force (naive algorithm) to check if a 16 bit long integer is prime or not and print all the prime numbers before it. number example: 1254786951475276. This is my code: import java.io.*; public class PrimeNumbers { …
Learner
  • 41
  • 3
0
votes
2 answers

AKS- Unable to compile 16 bit integer for primality check

I am trying to perform primality check on a 16 bit long number by using the AKS algorithm. I keep getting an error. Can someone please compile my codes and help me about where i am making a mistake. (number example which i want to compile:…
Learner
  • 41
  • 3
0
votes
1 answer

Determining if a number is prime in the above code

I have a simple problem: take a number and determine if it is prime. I cannot figure out why on earth the following does not work. def prime(x): for i in range (2, x): if x % i == 0: return False return…
k.dav
  • 59
  • 1
  • 6
0
votes
1 answer

How to design a Turing machine which checks whether a number is prime or not?

I could only make out that the logic must have included the logic of multiplication and division in Turing machines . But actually I cannot make out the exact solution.
vivek kumar
  • 19
  • 1
  • 3
0
votes
0 answers

Lucas numbers streaming on Scheme

To show how to check primality with the Lucas sequence, let’s look at an example. Consider the first few numbers in the Lucas sequence: 1,3,4,7,11,18,29,47,76,123,... If we are interested to see if a particular number, say 7, is prime, we…
0
votes
2 answers

is there a major inefficiency in this miller-rabin pseudocode in CLRS?

This question may actually have nothing to do with the Miller-Rabin primality testing procedure; it may only easy analysis of some simple pseudocode. On p 969 of CLRS (Introduction to Algorithms 3ed), an auxiliary function to Miller-Rabin is…
xdavidliu
  • 2,411
  • 14
  • 33
0
votes
1 answer

SICP Help me understand this

The following program finds the smallest integral divisor (greater than 1) of a given number n. It does this in a straightforward way, by testing n for divisibility by successive integers starting with 2. (define (smallest-divisor n) (find-divisor…
Martin
  • 9
  • 1
0
votes
1 answer

Fermat Primality Test Haskell

I have implemented the following two functions for establishing if n is a fermat prime number (will return n if its true, -1 if not), but it returns always -1, can't figure out why (gc is a funct taht calculates gcd) fermatPT :: Int -> Int fermatPT…
0
votes
1 answer

what is the highest prime number between 1 and 10001

So I'm trying to find the 10,001 prime number. Yes, its the euler #7 problem. The code i wrote appears to give me all the prime numbers from 3 to 10,001 but my answer is still incorrect. I know there are other questions about this that have been…
0
votes
0 answers

Issues With Miller-Rabin Test

I'm attempting to debug my implementation of the standard (i.e., probabilistic) Miller-Rabin test. This is the code right now, with a rudimentary test execution in the main method: #include #include typedef unsigned long long…
MrM21632
  • 27
  • 1
  • 8
0
votes
1 answer

How would I go about testing the primality of a large integer in R?

I have a 2500 digit integer which I need to determine the primality of. There are many methods in R for testing primality of 'small' numbers but the language doesn't seem to be suited for storing massive numbers. There are packages designed to store…
Tim Hargreaves
  • 292
  • 3
  • 11
0
votes
1 answer

Memory Error in Python Primality Testing program

def repeated(m, result, a, s, d): check = True r = 0 while r <= s - 1: if result == m - 1: check = False return check result = (result ** 2) % m r = r + 1 return check I need to write a primality testing python program…