We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 259203f commit dfd0423Copy full SHA for dfd0423
1 file changed
Algorithms/ComputeNumberOfDivisors.java
@@ -0,0 +1,23 @@
1
+class ComputeNumberOfDivisors {
2
+
3
+ // Function that calculates number of divisors
4
+ // Time Complexity : O( (n)^ 1/2 )
5
+ static int numberOfDivisors(int n) {
6
+ int count = 0;
7
+ for (int i = 1; i <= Math.sqrt(n); i++) {
8
+ if (n % i == 0) {
9
+ if (n / i == i) {
10
+ count++;
11
+ } else {
12
+ count += 2;
13
+ }
14
15
16
+ return count;
17
18
19
+ public static void main(String[] args) {
20
+ int x = 25;
21
+ System.out.println("Total number of divisor of " + x + " are " + numberOfDivisors(x));
22
23
+}
0 commit comments