primes

Erlang error on send to registered process

蹲街弑〆低调 提交于 2019-12-11 07:34:39
问题 I'm trying to make Erlang program that finds prime numbers with processes (ineffective, I know, but hey, it's just for fun :) ) - something along the lines of numbersimulation.com. On each "tick" the server spawns new process ("number") that increments its counter. If counter == that number, it's a factor, so we let server know. If server doesn't get any messages, it's a prime number. On small numbers (primes upto N, the server(50,L) line) it's okay, but on the bigger ones it crashes with:

What witnesses do i need for Rabin-Miller test for numbers up to 10¹⁸?

女生的网名这么多〃 提交于 2019-12-11 06:58:57
问题 What set of witnesses is sufficient for the Miller-Rabin test to be correct for all numbers up to 10¹⁸? I know that use of primes up to 17 as witnesses suffices for n < 341550071728321. 回答1: According to this record page, the set of 7 SPRP bases: {2, 325, 9375, 28178, 450775, 9780504, 1795265022} is sufficient for a deterministic test to at least n = 2^64 ( > 10^19) . 回答2: According to OEIS, use of witnesses up to 23 suffices for numbers up to 3825123056546413051 回答3: If you're willing to use

Printing the Largest Prime Factor of a Composite Number in C

独自空忆成欢 提交于 2019-12-11 06:44:12
问题 I was solving a puzzle, where im required to find the largest Prime Factor of a composite number entered by the user. I thought of something and have tried it out, but it doesn't manage to detect the largest prime factor amongst the factors of the composite number. I'm appending my code below, I'd be grateful if anyone could help me out here to get to detect the largest prime no. amongst the factors and print it. // Accept a composite number from user and print its largest prime factor.

My Haskell Solution to Euler #3 is Inefficient

爱⌒轻易说出口 提交于 2019-12-11 06:37:41
问题 I am attempting to solve Euler problem 3 in Haskell, which involves finding the largest prime factor of a number. My code runs for a long time and seems to hang. What is causing my code to be so grossly inefficient? primes = sieve (2:[3,5..]) where sieve (x:xs) = x:[y | y <- (sieve xs), mod y x /= 0] sieve [] = [] primefactors n = filter (\x -> mod n x == 0) (primesUnder n) where primesUnder z = reverse (takeWhile (< z) primes) solve3 = head (primefactors 600851475143) 回答1: Your main problem

How find a twin prime number from a range determined by the user in Fortran

被刻印的时光 ゝ 提交于 2019-12-11 06:35:42
问题 I want to make a program that finds twin prime numbers in a certain range, from n to m. Here it is what I have so far: program twin implicit none integer i, count1, n, m, count2, j, k, pri1, pri2 count1 = 0 count2 = 0 read(5,*)n read(5,*)m do i = 1,m do j = n,m if (mod(j,i) ==0) then count1 = count1 +1 else count1 = count1 if(count1 ==0) then pri1 = j do k=j,m if (mod(k,i)==0) then count2 = count2 +1 else count2 = count2 if(count2 ==0) then pri2 = k if (pri2-pri1 == 2) then write(*,*)j,k end

Boundless Arrays?

跟風遠走 提交于 2019-12-11 06:18:49
问题 I'm having some trouble. I wrote a code to find prime numbers up to a number, but for some reason, it gives me the error that I didn't define the number of elements in the array that I will be using. Is it possible to have an array where the number of elements isn't limited? Thanks :) #include <iostream> #include <cmath> #include <fstream> #include <cstdlib> using namespace std; int primer(int max); int main() { system("pause"); return 0; primer(1000); } int primer(int max){ int a[]=2; for

How do I define the sieve function for prime computation using higher–order functions?

两盒软妹~` 提交于 2019-12-11 05:11:58
问题 I have a recursive definition of sieve in Haskell for prime number computation. But I don’t know how to write the same function using higher–order functions such as map or filter . Can anybody show me please? sieve [] = [] sieve (x:xs) = check (x:xs) check [] = [] check (x:xs) |x/=2 && x/=3 && x/=5 && x/=7 = comp (x:xs) |otherwise = x : sieve xs comp [] = [] comp (x:xs) |x `mod` 2 == 0 = sieve xs |x `mod` 3 == 0 = sieve xs |x `mod` 5 == 0 = sieve xs |x `mod` 7 == 0 = sieve xs |otherwise = x :

What is the output of this condition in the Prime Function?

亡梦爱人 提交于 2019-12-11 04:46:58
问题 I found this code from another post and I'm trying to understand a part of this solution. function sumPrimes(n) { function isPrime(num) { for ( var i = 2; i < num; i++ ) { if ( num % i === 0 ) { return false; } } return true; } var arr = 2; for ( var i = 3; i <= n; i+=2 ) { if ( isPrime(i) ) { arr += i; } } return arr; } console.log(sumPrimes(10)); The part I'm asking about is this particular function function isPrime(num) { for ( var i = 2; i < num; i++ ) { if ( num % i === 0 ) { return

Merged iterators produce obscure results

不想你离开。 提交于 2019-12-11 03:47:44
问题 I'm trying to implement prime number generator using Sieve of Eratosthenes algorithm. I do it just to try using recursive iterator merging to implement sifter. What I do is this: from itertools import count,islice,groupby from heapq import merge def primes3(): p = 2 yield p sifter = (i*p for i in count(p)) s = next(sifter) for p in count(p+1): if p==s: # this p is sieved out print('s: {}'.format(s)) s = next(sifter) else: yield p # this is prime print('p: {}'.format(p)) sifter = (k for k, g

Prime numbers using Sieve of Atkin with BigInteger

≡放荡痞女 提交于 2019-12-11 03:39:12
问题 Does anyone happen to know of a C# Sieve of Atkin algorithm using BigInteger? From my understanding, this is the best known prime factorization algorithm currently in existence. I currently have this function: /// <summary> /// Finds prime numbers using the Sieve of Atkins algorithm. /// </summary> /// <param name="max">The limit of the prime list.</param> /// <returns>The list of prime numbers.</returns> public List<int> FindPrimes(int max) { var isPrime = new bool[max + 1]; var sqrt = (int)