Rosetta Code:CalmoSoft primes: Difference between revisions
Content deleted Content added
Created page with "'''Definition''' <br><br> Let p(1),p(2),p(3), ... ,p(n) be prime numbers, where p(n) < 100. If the sum of these primes is a prime number. then these numbers are called '''Calmo primes''' <br><br> '''Task''' <br><br> Find and show here the longest series of '''Calmo primes''' <br><br> =={{header|Ring}}== <syntaxhighlight lang="ring"> see "works..." + nl limit = 100 Primes = [] OldPrimes = [] NewPrimes = [] for p = 1 to limit if isPrime(p) add(Primes,p) ok n..." |
|||
Line 7: | Line 7: | ||
Find and show here the longest series of '''Calmo primes''' |
Find and show here the longest series of '''Calmo primes''' |
||
<br><br> |
<br><br> |
||
=={{header|Ring}}== |
|||
<syntaxhighlight lang="ring"> |
|||
see "works..." + nl |
|||
limit = 100 |
|||
Primes = [] |
|||
OldPrimes = [] |
|||
NewPrimes = [] |
|||
for p = 1 to limit |
|||
if isPrime(p) |
|||
add(Primes,p) |
|||
ok |
|||
next |
|||
lenPrimes = len(Primes) |
|||
for n = 1 to lenPrimes |
|||
num = 0 |
|||
OldPrimes = [] |
|||
for m = n to lenPrimes |
|||
num = num + Primes[m] |
|||
add(OldPrimes,Primes[m]) |
|||
if isPrime(num) |
|||
if len(OldPrimes) > len(NewPrimes) |
|||
NewPrimes = OldPrimes |
|||
ok |
|||
ok |
|||
next |
|||
next |
|||
str = "[" |
|||
for n = 1 to len(NewPrimes) |
|||
if n = len(NewPrimes) |
|||
str = str + newPrimes[n] + "]" |
|||
exit |
|||
ok |
|||
str = str + newPrimes[n] + ", " |
|||
next |
|||
sum = 0 |
|||
strsum = "" |
|||
for n = 1 to len(NewPrimes) |
|||
sum = sum + newPrimes[n] |
|||
if n = len(NewPrimes) |
|||
strsum = strsum + newPrimes[n] + " = " + sum + " is prime number" |
|||
exit |
|||
ok |
|||
strsum = strsum + newPrimes[n] + " + " |
|||
next |
|||
see str + nl |
|||
see strsum + nl |
|||
see "The length of the sequence of Calmo primes = " + len(NewPrimes) + nl |
|||
see "done.." + nl |
|||
func isPrime num |
|||
if (num <= 1) return 0 ok |
|||
if (num % 2 = 0 and num != 2) return 0 ok |
|||
for i = 3 to floor(num / 2) -1 step 2 |
|||
if (num % i = 0) return 0 ok |
|||
next |
|||
return 1 |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
works... |
|||
[7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89] |
|||
7 + 11 + 13 + 17 + 19 + 23 + 29 + 31 + 37 + 41 + 43 + 47 + 53 + 59 + 61 + 67 + 71 + 73 + 79 + 83 + 89 = 953 is prime number |
|||
The length of the sequence of Calmo primes = 21 |
|||
done.. |
|||
</pre> |
Revision as of 07:13, 7 April 2023
Definition
Let p(1),p(2),p(3), ... ,p(n) be prime numbers, where p(n) < 100. If the sum of these primes is a prime number. then these numbers are called Calmo primes
Task
Find and show here the longest series of Calmo primes