prime count function
This commit is contained in:
26
.vscode/launch.json
vendored
Normal file
26
.vscode/launch.json
vendored
Normal file
@@ -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
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
18
CMakeLists.txt
Normal file
18
CMakeLists.txt
Normal file
@@ -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.
|
||||||
27
src/primetest.cpp
Normal file
27
src/primetest.cpp
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#include<iostream>
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user