import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Main
{
public static long sb = 0;
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
while (sc.hasNext())
{
sb = 0;
int x = sc.nextInt();
if (x == 0)
{
break;
} else
{
dfs(1, x, 1);
}
}
}
public static void dfs(long x, int w, int gg)
{
if (sb != 0 || gg > 19)
{
return;
}
if (x % w == 0)
{
sb = x;
System.out.println(sb);
return;
}
dfs(x * 10, w, gg + 1);
dfs(x * 10 + 1, w, gg + 1);
}
}
E - Find The Multiple POJ - 1426 JAVA
最新推荐文章于 2021-08-04 15:15:41 发布
本文展示了一个使用Java实现的深度优先搜索(DFS)算法示例,该算法用于寻找特定条件下满足要求的数字。通过递归调用,算法尝试通过在数字末尾添加0或1来构建满足条件的数字。

1175

被折叠的 条评论
为什么被折叠?



