diff options
| author | Paul Jungeblut <s_jungeb@i08pc55.atis-stud.uni-karlsruhe.de> | 2014-11-24 15:32:56 +0100 |
|---|---|---|
| committer | Paul Jungeblut <s_jungeb@i08pc55.atis-stud.uni-karlsruhe.de> | 2014-11-24 15:32:56 +0100 |
| commit | 9132c2f869e166f871027a99d1746f712397ce08 (patch) | |
| tree | f51aaed4aab3d8cb2bbb1ac11cb7d474f7ac15ed /math | |
| parent | cb1ed059fe6d3518436d32160e51c84d4517ea26 (diff) | |
small fixes
Diffstat (limited to 'math')
| -rw-r--r-- | math/factor.cpp | 34 | ||||
| -rw-r--r-- | math/math.tex | 6 | ||||
| -rw-r--r-- | math/primeSieve.cpp | 15 |
3 files changed, 10 insertions, 45 deletions
diff --git a/math/factor.cpp b/math/factor.cpp index 43aeae3..0e5d7d8 100644 --- a/math/factor.cpp +++ b/math/factor.cpp @@ -1,27 +1,5 @@ -#include <iostream> -#include <vector> - -using namespace std; - -typedef unsigned long long ll; - const ll PRIME_SIZE = 10000000; -vector<int> primes; - -//Call before calculating anything -void primeSieve() { - vector<int> isPrime(PRIME_SIZE,true); - for(ll i = 2; i < PRIME_SIZE; i+=2) { - if(isPrime[i]) { - primes.push_back(i); - if(i*i <= PRIME_SIZE) { - for(ll j = i; i*j < PRIME_SIZE; j+=2) isPrime[i*j] = false; - } - } - if(i == 2) - i--; - } -} +vector<int> primes; //call primeSieve(PRIME_SIZE); before //Factorize the number n vector<int> factorize(ll n) { @@ -33,13 +11,9 @@ vector<int> factorize(ll n) { num /= primes[pos]; factor.push_back(primes[pos]); } - else - pos++; - if(primes[pos]*primes[pos] > n) - break; + else pos++; + if(primes[pos]*primes[pos] > n) break; } - if(num != 1) - factor.push_back(num); + if(num != 1) factor.push_back(num); return factor; - } diff --git a/math/math.tex b/math/math.tex index ca67f0e..feb89ff 100644 --- a/math/math.tex +++ b/math/math.tex @@ -17,6 +17,9 @@ Sei $0 \leq x < n$. Definiere $d := gcd(x, n)$. \end{description} \lstinputlisting{math/multInv.cpp} +\subsection{Primzahlsieb von Eratosthenes} +\lstinputlisting{math/primeSieve.cpp} + \subsubsection{Faktorisierung} \lstinputlisting{math/factor.cpp} @@ -29,9 +32,6 @@ Sei $0 \leq x < n$. Definiere $d := gcd(x, n)$. \subsection{Binomialkoeffizienten} \lstinputlisting{math/binomial.cpp} -\subsection{Primzahlsieb von Eratosthenes} -\lstinputlisting{math/primeSieve.cpp} - \subsection{Satz von \textsc{Sprague-Grundy}} Weise jedem Zustand $X$ wie folgt eine \textsc{Grundy}-Zahl $g\left(X\right)$ zu: \[ diff --git a/math/primeSieve.cpp b/math/primeSieve.cpp index 4c82bbe..db96e5b 100644 --- a/math/primeSieve.cpp +++ b/math/primeSieve.cpp @@ -1,12 +1,5 @@ -#include <iostream> -#include <vector> - -using namespace std; - -typedef unsigned long long ll; - -vector<int> primeSieve(ll n) { - vector<int> primes; +vector<int> primes; +void primeSieve(ll n) { //berechnet die Primzahlen kleiner n vector<int> isPrime(n,true); for(ll i = 2; i < n; i+=2) { if(isPrime[i]) { @@ -15,8 +8,6 @@ vector<int> primeSieve(ll n) { for(ll j = i; i*j < n; j+=2) isPrime[i*j] = false; } } - if(i == 2) - i--; + if(i == 2) i--; } - return primes; } |
