forked from Red-0111/Anything-Repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsalesforce1.java
48 lines (40 loc) · 1.12 KB
/
salesforce1.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
40
41
42
43
44
45
46
47
import java.util.*;
public class salesforce1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int i=0;i<T;i++){
int N = sc.nextInt();
System.out.println(fun2(N));
}
}
private static int fun2(int N){
ArrayList<Integer> graph[]=new ArrayList[N+1];
for(int i=1;i<graph.length;i++){
graph[i]=new ArrayList<>();
}
for(int j=1;j<graph.length;j++){
for(int i=1;i<graph.length;i++){
if(j>i && j%i==0) graph[i].add(j);
}
}
boolean visited[]=new boolean[N+1];
count=0;
dfs(1, visited, graph,N);
return count;
}
static int count=0;
private static void dfs(int i,boolean[] visited,ArrayList<Integer> graph[],int N){
if(i==N){
count++;
return;
}
visited[i]=true;
for(int node:graph[i]){
if(visited[node]==false){
dfs(node,visited,graph,N);
}
}
visited[i]=false;
}
}