Dateien nach „BSP_1_F“ hochladen
This commit is contained in:
commit
40e2b29d95
5 changed files with 212 additions and 0 deletions
44
BSP_1_F/bsp_1_f.cpp
Normal file
44
BSP_1_F/bsp_1_f.cpp
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#include "bsp_1_f.h"
|
||||
#include "mayer_primes.h"
|
||||
#include "algorithm"
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int single_goldbach(const int &k)
|
||||
{
|
||||
vector<int> primes = get_primes(k);
|
||||
int amount = 0;
|
||||
for(size_t it = 0; primes[it]<=k/2.0; ++it) //für Primzahl größer als k/2 haben wir bereits Zerlegung gezählt: 3+7 = 7+3
|
||||
{
|
||||
for(size_t j = it; j<primes.size(); ++j)
|
||||
{
|
||||
if(primes[it] + primes[j] == k)
|
||||
{
|
||||
amount += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return amount;
|
||||
}
|
||||
|
||||
|
||||
vector<int> count_goldbach(const int &n)
|
||||
{
|
||||
vector<int> count_vec((n-4)/2+1,0);
|
||||
vector<int> primes = get_primes(n);
|
||||
for(size_t k=0; k < primes.size() && primes[k]<=n/2; ++k)
|
||||
{
|
||||
for(size_t i=k; i<primes.size(); ++i)
|
||||
{
|
||||
int sum = primes[k] + primes[i];
|
||||
if(sum<=n)
|
||||
{
|
||||
count_vec[(sum-4)/2] += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return count_vec;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue