-
Notifications
You must be signed in to change notification settings - Fork 1
/
minimum-distance.cpp
68 lines (53 loc) · 1.19 KB
/
minimum-distance.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
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int minDistance(int number)
{
int factors[50] = {};
int count = 0;
for (int i = 1; i <= number; i++)
{
if ((number % i) == 0)
{
factors[count] = i;
count++;
}
}
int mdistance = factors[count - 1] - factors[0];
for (int j = 0; j < count - 1; j++)
{
int d = 0;
for (int p = j + 1; p < count; p++)
{
d = factors[p] - factors[j];
if (d < mdistance)
{
mdistance = d;
}
}
}
}
int min(int arr, int len){
for(int i = 1; i < len ; i++){
int position = i;
int currentValue = arr[i];
while(position >= 0 && arr[position -1] > currentValue){
arr[position] = arr[position - 1];
position--;
}
arr[position] = currentValue;
}
return arr[1] - arr[0];
}
int main()
{
int number = 8;
int vector<int> factors;
for(int i = 1; i <= number ; i++){
if(number % i == 0){
factors.push_back(i);
}
}
cout << min(factors, factors.size());
return 0;
}