diff --git a/vector/a.out b/vector/a.out deleted file mode 100755 index a65fffb..0000000 Binary files a/vector/a.out and /dev/null differ diff --git a/vector/question.txt b/vector/question.txt index 7286425..0f924eb 100644 --- a/vector/question.txt +++ b/vector/question.txt @@ -2,7 +2,7 @@ Determine all positive integers that evenly divide into a number, that is it's f Return the pth element of your list, sorted ascending. If there is no pth element, return 0 For example, given number n = 20, it's factors are {1, 2, 4, 5, 10, 20}. Using 1-based indexing, if p = 3 return 4. -If p = 6, return 0 +If p = 6, return 20 1 <= n <= 10 ^ 15 1 <= p <= 10 ^ 9 diff --git a/vector/sol.cpp b/vector/sol.cpp index 334b3d2..9e83aee 100644 --- a/vector/sol.cpp +++ b/vector/sol.cpp @@ -7,7 +7,8 @@ long pthFactor(long n, long p) { for(i = 1; (i * i) <= n; i++) { if(n % i == 0) { v.push_back(i); - v.push_back(n / i); + if(i != n/i) + v.push_back(n / i); } } if(v.size() < p) @@ -22,4 +23,4 @@ int main(int argc, char const *argv[]) { long long p; cin >> p; cout << pthFactor(n, p) << endl; -} \ No newline at end of file +}