Jump to content

Equal prime and composite sums: Difference between revisions

Equal prime and composite sums in FreeBASIC
m (Promote. multiple implementations, little controversy)
(Equal prime and composite sums in FreeBASIC)
Line 139:
Primes up to 390180569 at position 20840220 and composites up to 91491160 at position 86192660 sum to 3950430820867201.
</pre>
 
 
=={{header|FreeBASIC}}==
{{trans|XPL0}}
<lang freebasic>#include "isprime.bas"
 
Dim As Integer i = 0
Dim As Integer IndN = 1, IndM = 1
Dim As Integer NumP = 2, NumC = 4
Dim As Integer SumP = 2, SumC = 4
Print " sum prime sum composite sum"
Do
If SumC > SumP Then
Do
NumP += 1
Loop Until isPrime(NumP)
SumP += NumP
IndN += 1
End If
If SumP > SumC Then
Do
NumC += 1
Loop Until Not isPrime(NumC)
SumC += NumC
IndM += 1
End If
If SumP = SumC Then
Print Using "##,###,###,###,### - ##,###,### - ##,###,###"; SumP; IndN; IndM
i += 1
If i >= 9 Then Exit Do
Do
NumC += 1
Loop Until Not isPrime(NumC)
SumC += NumC
IndM += 1
End If
Loop</lang>
{{out}}
<pre> sum prime sum composite sum
10 - 3 - 2
1,988 - 33 - 51
14,697 - 80 - 147
83,292 - 175 - 361
1,503,397 - 660 - 1,582
18,859,052 - 2,143 - 5,699
93,952,013 - 4,556 - 12,821
89,171,409,882 - 118,785 - 403,341
9,646,383,703,961 - 1,131,142 - 4,229,425</pre>
 
=={{header|Go}}==
{{trans|Wren}}
2,131

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.