-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest1.cpp
More file actions
35 lines (34 loc) · 774 Bytes
/
test1.cpp
File metadata and controls
35 lines (34 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
using namespace std;
bool primo (int n){
bool condicion;
if(n != 1 && n != 0){
for(int i = 2; i <= n ; i++){
if(n % i == 0){
if(n == i){
condicion = true;
}
else {
condicion = false;
return condicion;
}
}
}
}
else condicion = false;
return condicion;
}
int main(){
int n;
int count = 0;
cin>>n;
clock_t startTime = clock();
for(int i = 1 ; i <=n ; i++){
if(primo(i)){
count += 1;
}
}
cout << count << '\n';
cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " Segundos." << endl;
return 0;
}