commit 0d1a549eebbcdfb0843db009c96a282f15d79446 Author: Sherwin Price Date: Tue Apr 15 18:46:37 2025 -0400 prime count function diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..f04c78e --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Debug (gdb Launch)", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/primetest.exe", + "args": [], + "stopAtEntry": true, + "cwd": "${workspaceFolder}", + "environment": [], + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e8bedea --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,18 @@ +# 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. diff --git a/src/primetest.cpp b/src/primetest.cpp new file mode 100644 index 0000000..15c7bc5 --- /dev/null +++ b/src/primetest.cpp @@ -0,0 +1,27 @@ +#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; + } +}; + +int main(int argc, char** argv){ + std::cout << Solution::countPrime(50000) << std::endl; + +} \ No newline at end of file