-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProductWays.java
More file actions
25 lines (23 loc) · 802 Bytes
/
ProductWays.java
File metadata and controls
25 lines (23 loc) · 802 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
import java.util.*;
public class WaysProduct {
public static int countWays(int n) {
int count = 0;
for (int i = 1; i <= Math.sqrt(n); i++) {
if (n % i == 0) {
if (n / i != i) {
count++;
}
}
}
return count;
}
public static void main(String[] args) {
Scanner obj = new Scanner(System.in);
System.out.print("Enter a positive integer: ");
int number = obj.nextInt();
int ways = countWays(number);
System.out.println("Number of ways to represent " + number + " as the product of two distinct numbers: " + ways);
}
}
//Can also be used to check prime as number of ways would be 1
// combination should be unique 7*2 and 2*7 is considerd same