dfs搜索:
代码如下:
import java.util.Scanner;
public class _找数字 {
static int n;
static boolean ok;
static void dfs(long x,int cnt){
if(cnt>=19)
return;
if(ok)
return;
if(x%n==0){
ok=true;
System.out.println(x);
return;
}
dfs(x*10+0,cnt+1);
dfs(x*10+1,cnt+1);
}
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
dfs(1,0);
}
}