-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move generate_phi.hpp code phi_vector.cpp (#74)
- Loading branch information
1 parent
eb3f1f5
commit 80a6ad9
Showing
8 changed files
with
100 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/// | ||
/// @file phi_vector.hpp | ||
/// | ||
/// Copyright (C) 2024 Kim Walisch, <[email protected]> | ||
/// | ||
/// This file is distributed under the BSD License. See the COPYING | ||
/// file in the top level directory. | ||
/// | ||
|
||
#ifndef PHI_VECTOR_HPP | ||
#define PHI_VECTOR_HPP | ||
|
||
#include <PiTable.hpp> | ||
#include <Vector.hpp> | ||
#include <stdint.h> | ||
|
||
namespace primecount { | ||
|
||
/// Returns a vector with phi(x, i - 1) values such that | ||
/// phi[i] = phi(x, i - 1) for 1 <= i <= a. | ||
/// phi(x, a) counts the numbers <= x that are not | ||
/// divisible by any of the first a primes. | ||
/// | ||
Vector<int64_t> phi_vector(int64_t x, | ||
int64_t a, | ||
const Vector<uint32_t>& primes, | ||
const PiTable& pi); | ||
|
||
/// Returns a vector with phi(x, i - 1) values such that | ||
/// phi[i] = phi(x, i - 1) for 1 <= i <= a. | ||
/// phi(x, a) counts the numbers <= x that are not | ||
/// divisible by any of the first a primes. | ||
/// | ||
Vector<int64_t> phi_vector(int64_t x, | ||
int64_t a, | ||
const Vector<int64_t>& primes, | ||
const PiTable& pi); | ||
|
||
} // namespace | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
/// | ||
/// @file generate_phi.cpp | ||
/// @brief Test that generate_phi(x, a) and phi(x, a) | ||
/// @file phi_vector.cpp | ||
/// @brief Test that phi_vector(x, a) and phi(x, a) | ||
/// results are identical | ||
/// | ||
/// Copyright (C) 2017 Kim Walisch, <[email protected]> | ||
/// Copyright (C) 2024 Kim Walisch, <[email protected]> | ||
/// | ||
/// This file is distributed under the BSD License. See the COPYING | ||
/// file in the top level directory. | ||
/// | ||
|
||
#include <primecount.hpp> | ||
#include <generate.hpp> | ||
#include <generate_phi.hpp> | ||
#include <imath.hpp> | ||
#include <phi_vector.hpp> | ||
#include <PiTable.hpp> | ||
|
||
#include <stdint.h> | ||
|
@@ -38,7 +39,7 @@ int main() | |
int64_t a = pi[y]; | ||
|
||
auto primes = generate_primes<int64_t>(y); | ||
auto phi_vect = generate_phi(x, a, primes, pi); | ||
auto phi_vect = phi_vector(x, a, primes, pi); | ||
|
||
for (size_t i = 1; i < phi_vect.size(); i++) | ||
{ | ||
|
@@ -47,7 +48,7 @@ int main() | |
|
||
if (phi1 != phi2) | ||
{ | ||
std::cerr << "Error: generate_phi(x, i - 1) = " << phi1 << std::endl; | ||
std::cerr << "Error: phi_vector(x, i - 1) = " << phi1 << std::endl; | ||
std::cerr << "Correct: phi(x, i - 1) = " << phi2 << std::endl; | ||
std::cerr << "x = " << x << std::endl; | ||
std::cerr << "i - 1 = " << i - 1 << std::endl; | ||
|