Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed vector/a.out
Binary file not shown.
2 changes: 1 addition & 1 deletion vector/question.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions vector/sol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -22,4 +23,4 @@ int main(int argc, char const *argv[]) {
long long p;
cin >> p;
cout << pthFactor(n, p) << endl;
}
}