Data update
This commit is contained in:
parent
35bcdeebf8
commit
74c69a0df6
2427 changed files with 31826 additions and 3468 deletions
|
|
@ -26,5 +26,5 @@ function g(n)
|
|||
if isPrime(i) = 1 and isPrime(n - i) = 1 then cont += 1
|
||||
next i
|
||||
end if
|
||||
g = cont
|
||||
return cont
|
||||
end function
|
||||
|
|
|
|||
28
Task/Goldbachs-comet/Gambas/goldbachs-comet-1.gambas
Normal file
28
Task/Goldbachs-comet/Gambas/goldbachs-comet-1.gambas
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
Use "isprime.bas"
|
||||
|
||||
Public Sub Main()
|
||||
|
||||
Print "The first 100 G numbers are:"
|
||||
|
||||
Dim n As Integer, col As Integer = 1
|
||||
For n = 4 To 202 Step 2
|
||||
Print Format$(Str(g(n)), "####");
|
||||
If col Mod 10 = 0 Then Print
|
||||
col += 1
|
||||
Next
|
||||
|
||||
Print "\nG(1.000.000) = "; g(1000000)
|
||||
|
||||
End
|
||||
|
||||
Function g(n As Integer) As Integer
|
||||
|
||||
Dim i As Integer, count As Integer = 0
|
||||
If n Mod 2 = 0 Then
|
||||
For i = 2 To n \ 2 '(1/2) * n
|
||||
If isPrime(i) And isPrime(n - i) Then count += 1
|
||||
Next
|
||||
End If
|
||||
Return count
|
||||
|
||||
End Function
|
||||
23
Task/Goldbachs-comet/Yabasic/goldbachs-comet-1.basic
Normal file
23
Task/Goldbachs-comet/Yabasic/goldbachs-comet-1.basic
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import isprime
|
||||
|
||||
print "The first 100 G numbers are:"
|
||||
|
||||
col = 1
|
||||
for n = 4 to 202 step 2
|
||||
print g(n) using ("####");
|
||||
if mod(col, 10) = 0 print
|
||||
col = col + 1
|
||||
next n
|
||||
|
||||
print "\nG(1000000) = ", g(1000000)
|
||||
end
|
||||
|
||||
sub g(n)
|
||||
count = 0
|
||||
if mod(n, 2) = 0 then
|
||||
for i = 2 to (1/2) * n
|
||||
if isPrime(i) and isPrime(n - i) count = count + 1
|
||||
next i
|
||||
fi
|
||||
return count
|
||||
end sub
|
||||
46
Task/Goldbachs-comet/Yabasic/goldbachs-comet-2.basic
Normal file
46
Task/Goldbachs-comet/Yabasic/goldbachs-comet-2.basic
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
std::vector<bool> primes;
|
||||
|
||||
void initialise_primes(const int32_t& limit) {
|
||||
primes.resize(limit);
|
||||
for ( int32_t i = 2; i < limit; ++i ) {
|
||||
primes[i] = true;
|
||||
}
|
||||
|
||||
for ( int32_t n = 2; n < sqrt(limit); ++n ) {
|
||||
for ( int32_t k = n * n; k < limit; k += n ) {
|
||||
primes[k] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t goldbach_function(const int32_t& number) {
|
||||
if ( number <= 2 || number % 2 == 1 ) {
|
||||
throw std::invalid_argument("Argument must be even and greater than 2: " + std::to_string(number));
|
||||
}
|
||||
|
||||
int32_t result = 0;
|
||||
for ( int32_t i = 1; i <= number / 2; ++i ) {
|
||||
if ( primes[i] && primes[number - i] ) {
|
||||
result++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int main() {
|
||||
initialise_primes(2'000'000);
|
||||
|
||||
std::cout << "The first 100 Goldbach numbers:" << std::endl;
|
||||
for ( int32_t n = 2; n < 102; ++n ) {
|
||||
std::cout << std::setw(3) << goldbach_function(2 * n) << ( n % 10 == 1 ? "\n" : "" );
|
||||
}
|
||||
|
||||
std::cout << "\n" << "The 1,000,000th Goldbach number = " << goldbach_function(1'000'000) << std::endl;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue