diff --git a/CMakeLists.txt b/CMakeLists.txt index e8bedea..288643f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,18 +1,13 @@ -# CMakeList.txt : CMake project for xtfs, include source and define -# project specific logic here. -# -cmake_minimum_required (VERSION 3.16) - - -project ("primetest") - -# Add source to this project's executable.s - -add_executable (primetest "src/primetest.cpp") - -set_property(TARGET primetest PROPERTY CXX_STANDARD 17) -set_property(TARGET primetest PROPERTY CXX_STANDARD_REQUIRED ON) -set_property(TARGET primetest PROPERTY CXX_EXTENSIONS OFF) - - -# TODO: Add tests and install targets if needed. +# CMakeList.txt : CMake project for xtfs, include source and define +# project specific logic here. +# +cmake_minimum_required (VERSION 3.16) + + +project (primetest VERSION 1.0 LANGUAGES CXX) + +set_property(TARGET PROPERTY CXX_STANDARD 21) +set_property(TARGET PROPERTY CXX_STANDARD_REQUIRED ON) +set_property(TARGET PROPERTY CXX_EXTENSIONS OFF) + +add_subdirectory(src) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..89ff6dd --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,8 @@ +# CMakeList.txt + +add_executable(primetest primetest.cpp) + +add_subdirectory(prime) + + +target_link_libraries( primetest PRIVATE prime ) \ No newline at end of file diff --git a/src/prime/CMakeLists.txt b/src/prime/CMakeLists.txt new file mode 100644 index 0000000..a1d8966 --- /dev/null +++ b/src/prime/CMakeLists.txt @@ -0,0 +1,16 @@ +# CMakeList.txt + +add_library(prime "") + +target_sources(prime + PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/prime.cpp + PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/prime.hpp +) + +target_include_directories(prime + + PUBLIC + ${CMAKE_CURRENT_LIST_DIR} +) \ No newline at end of file diff --git a/src/prime/prime.cpp b/src/prime/prime.cpp new file mode 100644 index 0000000..d2b2aae --- /dev/null +++ b/src/prime/prime.cpp @@ -0,0 +1,17 @@ +#include "prime.hpp" + +int Prime::count(int n){ + int cntout = 0; + for( int icnt = 2; ( icnt <= n ); icnt++ ){ + int ts = 0; + for ( int it=icnt; it > 1; --it ){ + if( (icnt % it) == 0 ) { + ts = ts + 1; + } + } + if( ts==1 ){ + cntout = cntout + 1; + } + } + return cntout; +} diff --git a/src/prime/prime.hpp b/src/prime/prime.hpp new file mode 100644 index 0000000..e6771a6 --- /dev/null +++ b/src/prime/prime.hpp @@ -0,0 +1,9 @@ +#ifndef PRIME_HPP +#define PRIME_HPP + +class Prime { + public: + static int count(int n); +}; + +#endif \ No newline at end of file diff --git a/src/primetest.cpp b/src/primetest.cpp index 15c7bc5..dbe50ff 100644 --- a/src/primetest.cpp +++ b/src/primetest.cpp @@ -1,27 +1,10 @@ #include +#include using std::cout; - -class Solution { - public: - static int countPrime(int n){ - int cntout = 0; - for( int icnt = 2; ( icnt <= n ); icnt++ ){ - int ts = 0; - for ( int it=icnt; it > 1; --it ){ - if( (icnt % it) == 0 ) { - ts = ts + 1; - } - } - if( ts==1 ){ - cntout = cntout + 1; - } - } - return cntout; - } -}; +using std::endl; int main(int argc, char** argv){ - std::cout << Solution::countPrime(50000) << std::endl; + std::cout << Prime::count(50000) << std::endl; } \ No newline at end of file