How to resolve the algorithm Erdös-Selfridge categorization of primes step by step in the Sidef programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Erdös-Selfridge categorization of primes step by step in the Sidef programming language
Table of Contents
Problem Statement
A prime p is in category 1 if the prime factors of p+1 are 2 and or 3. p is in category 2 if all the prime factors of p+1 are in category 1. p is in category g if all the prime factors of p+1 are in categories 1 to g-1. The task is first to display the first 200 primes allocated to their category, then assign the first million primes to their category, displaying the smallest prime, the largest prime, and the count of primes allocated to each category.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Erdös-Selfridge categorization of primes step by step in the Sidef programming language
Source code in the sidef programming language
func Erdös_Selfridge_class(n, s=1) is cached {
var f = factor_exp(n+s)
f.last.head > 3 || return 1
f.map {|p| __FUNC__(p.head, s) }.max + 1
}
say "First two hundred primes; Erdös-Selfridge categorized:"
200.pn_primes.group_by(Erdös_Selfridge_class).sort_by{.to_i}.each_2d {|k,v|
say "#{k} => #{v}"
}
say "\nSummary of first 10^6 primes; Erdös-Selfridge categorized:";
1e6.pn_primes.group_by(Erdös_Selfridge_class).sort_by{.to_i}.each_2d {|k,v|
printf("Category %2d: first: %9s last: %10s count: %s\n", k, v.first, v.last, v.len)
}
You may also check:How to resolve the algorithm Gray code step by step in the Lobster programming language
You may also check:How to resolve the algorithm Pick random element step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Wordiff step by step in the 11l programming language
You may also check:How to resolve the algorithm Stern-Brocot sequence step by step in the Phix programming language
You may also check:How to resolve the algorithm Sum and product puzzle step by step in the Haskell programming language