From 1 to 9, nine digits form a nine-digit number. If one digit is extracted from the left, it must be divisible by one. The number composed of two digits can be divisible by two, the number composed of three digits can be divided by three, and so on.

Source: Internet
Author: User

From 1 to 9, the nine digits form a nine-digit number with no duplicates. If a number is extracted from the left, it must be divisible by 1. The number composed of two numbers can be divisible by 2. The number composed of three numbers can be divisible by 3, and so on... The number of each fetch is obtained from the left. Q: What is this number? Returns the numberAlgorithm.

 

CodeAs follows:

Import Java. util. arrays; </P> <p> public class magicdiv {<br/> private int [] used = new int [10]; <br/> Public void find () {<br/> arrays. fill (used, 0); <br/> used [5] = 1; <br/> DFS (0, 1 ); <br/>}< br/> Public void DFS (INT pre, int POS) {<br/> If (Pos> 9) {<br/> system. out. println (pre); <br/> return; <br/>}< br/> int TMP = Pre * 10; <br/> If (Pos = 5) {<br/> DFS (TMP + 5, POS + 1); <br/>}else {</P> <p> for (INT I = 1; I <10; I ++) {<br/> If (used [I] = 0) {<br/> int cur = TMP + I; <br/> If (cur % Pos = 0) {<br/> used [I] = 1; <br/> DFS (cur, POS + 1 ); <br/> used [I] = 0; <br/>}</P> <p >}< br/> Public static void main (string [] ARGs) {<br/> New magicdiv (). find (); <br/>}</P> <p>}

 

 

From: http://yangguo.javaeye.com/blog/801820

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.