primality-test Questions
32
I would just like to ask if this is a correct way of checking if number is prime or not? because I read that 0 and 1 are NOT a prime number.
int num1;
Console.WriteLine("Accept number:");
num1 =...
Guerrero asked 1/4, 2013 at 12:7
5
I can't seem to make random prime numbers using this code, please can someone help me?
def RandomPrime():
prime = False
while prime == False:
n = random.randint(10000, 100000)
if n % 2 != 0:
...
Chauffer asked 10/1, 2014 at 11:23
6
So I have devised the following function for seeing if a given number is a prime in Haskell (it assumes the first prime is 2):
isPrime k = length [ x | x <- [2..k], k `mod` x == 0] == 1
it ha...
Tango asked 14/1, 2011 at 11:54
13
Solved
To test whether a number is prime or not, why do we have to test whether it is divisible only up to the square root of that number?
Contain asked 27/4, 2011 at 22:1
1
What would be the time complexity of this function
bool prime(int n) {
if(n <= 1) {
return false;
} else if(n <= 3) {
return true;
} else if(n % 2 == 0 || n % 3 == 0) {
return false;
}...
Rost asked 14/7, 2020 at 14:20
1
Solved
I wrote isPrime function. It checks if a given number is prime or not.
The last "prime" list is given separately.
prime :: [Integer]
prime = 2 : filter isPrime [3..]
isPrime :: Integer -> Bool
...
Stroud asked 30/10, 2017 at 10:12
5
Given n, find m such that m is the smallest semiprime greater than n.
Next prime is pretty straightforward, semiprime is less so. To be clear, only the semiprime is needed, though getting the f...
Dufour asked 26/2, 2017 at 19:11
3
Solved
I am trying to learn lisp and I have some difficulties with prime numbers. I need a function is-prime and if it is prime I have to return t and if it is not I have to return nil.
(prime 41) =>...
Masturbate asked 15/12, 2013 at 22:16
5
I know the Miller–Rabin primality test is probabilistic. However I want to use it for a programming task that leaves no room for error.
Can we assume that it is correct with very high probability ...
Invulnerable asked 7/6, 2014 at 10:41
2
Solved
I'm searching for an algorithm to primality test large (like 10200) numbers.
Are there any good algorithms?
Ideally, I'd prefer an algorithm that isn't probabalistic.
Note: Numbers have over 50...
Grammarian asked 5/2, 2012 at 19:56
3
Solved
As an exercise for myself, I'm implementing the Miller-Rabin test. (Working through SICP). I understand Fermat's little theorem and was able to successfully implement that. The part that I'm gettin...
Hygroscope asked 17/9, 2010 at 7:24
1
I have the following code which determines whether a number is prime:
public static boolean isPrime(int n){
boolean answer = (n>1)? true: false;
for(int i = 2; i*i <= n; ++i)
{
System.o...
Zippora asked 20/10, 2013 at 17:35
2
Solved
Im trying to implement the Miller-Rabin primality test according to the description in FIPS 186-3 C.3.1. No matter what I do, I cannot get it to work. The instructions are pretty specific, and I do...
Principled asked 28/6, 2012 at 0:54
3
I was reading about the prime test algorithm and found the AKS primality test. Could this algorithm be implemented in Scheme or in C++?
Has anyone tried implementing the AKS test?
Suberin asked 27/6, 2011 at 18:43
3
I'm currently going through the book "The Haskell Road to Logic, Math, and Programming" by Doets and Van Eijck. I've never been exposed to any functional programming language until this book, so ke...
Jordan asked 17/8, 2010 at 19:42
1
© 2022 - 2024 — McMap. All rights reserved.