-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5.cpp
72 lines (61 loc) · 1.16 KB
/
5.cpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
*/
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
#define k 20
bool isPrime(int number){
bool flag = false;
for(int i=2; i<=sqrt(number); ++i)
{
// condition for nonprime number
if(number%i==0)
{
flag=true;
break;
}
}
return !flag;
}
vector<int> getPrimes(int n){
vector<int> v;
for(int i = 2; i<n; i++){
if(isPrime(i)){
v.push_back(i);
}
}
return v;
}
int digni(int b, int e){
int r = 1;
for(int i = 0; i<e; i++){
r*=b;
}
return r;
}
int main(void){
vector<int> p = getPrimes(k);
int N = 1;
int i = 0;
bool check = true;
int limit = (int)sqrt(k);
while(i<p.size()){
int a = 1;
if(check){
if( p[i] <= limit){
a = floor( log(k) / log(p[i]) );
}else{
check = false;
}
}
cout <<p[i] << " " << a << " " << N << endl;
cout << digni(p[i], a) << endl;
N = N* digni(p[i], a);
i++;
}
cout << N;
return 0;
}