-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblemnumber26.cpp
More file actions
42 lines (37 loc) · 907 Bytes
/
problemnumber26.cpp
File metadata and controls
42 lines (37 loc) · 907 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
36
37
38
39
40
41
42
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
#include <string>
using namespace std;
//function Count the number of divisors of a positive integer n.
int divisors(int n) {
int result = 0;
for (int i = 1; i <= n; i++)
{
if (n % i == 0)
{
result++;
}
else
{
continue;
}
}
return result;
}
int main() {
cout << divisors(4096);
return 1;
}
/*Count the number of divisors of a positive integer n.
Random tests go up to n = 500000.
Examples (input --> output)
4 --> 3 // we have 3 divisors - 1, 2 and 4
5 --> 2 // we have 2 divisors - 1 and 5
12 --> 6 // we have 6 divisors - 1, 2, 3, 4, 6 and 12
30 --> 8 // we have 8 divisors - 1, 2, 3, 5, 6, 10, 15 and 30
Note you should only return a number, the count of divisors. The numbers between parentheses are shown only for you to see which numbers are counted in each case.
Number Theory
Mathematics
Funda*/