-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path29_November.java
39 lines (38 loc) · 965 Bytes
/
29_November.java
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
class Solution {
public static int numoffbt(int arr[], int n)
{
// Your code goes here
int min=Integer.MAX_VALUE;
int max=1;
for(int i:arr)
{
min=Math.min(min,i);
max=Math.max(max,i);
}
int []dp=new int[max+1];
for(int i:arr)
{
dp[i]=1;
}
int ans=0;
for(int i=min;i<=max;i++)
{
if (dp[i]!=0)
{
for(int j=i+i;j<=max &&(j/i)<=i;j+=i)
{
if (dp[j]!=0)
{
dp[j]+=(dp[i]*dp[j/i]);
if(i != (j/i))
{
dp[j]+=(dp[i]*dp[j/i]);
}
}
}
ans+=dp[i]%1000000007;
}
}
return ans%1000000007;
}
}