Find an integer that matches the criteria __ Find an integer that matches the criteria

Source: Internet
Author: User

Question: Arbitrarily given a positive integer n, a minimum positive integer M (m>1) is obtained so that the N*m decimal representation contains only 1 and 0.

Solution one. General Positive Thinking


Solution two. Reverse thinking: Finding the conditions of known results


The code implementation is as follows:

Initialize for (i = 0; i < N; i++) bigint[i].clear ();

     Bigint[1].push_back (0); 
     int noupdate = 0;
          for (i=1,j=10%n;; i++,j= (j*10)%N) {BOOL flag = false;
               if (bigint[j].size () = = 0) {flag = true;
               BIGINT[J] = 10^i, (10^i% N = j) bigint[j].clear ();
          Bigint[j].push_back (i); for (k = 1; k < N; k++) {if (bigint[k].size () > 0) &&am P
               (I > Bigint[k][bigint[k].size ()-1]) && (bigint[(k + j)% n].size () = = 0))
                    {//bigint[(k + j)% N] = 10^i + bigint[k] flag = true;
                    bigint[(k + j)% N] = bigint[k];
               bigint[(k + j)% N].push_back (i);
       } if (flag = false) noupdate++;
          else noupdate=0;
   If you have not been able to update the bigint through a circular section, there is no solution, jump out.       or bigint[0]!= NULL, has found the solution, also jumped out. if (noupdate = N | |
     Bigint[0].size () > 0) break; } if (bigint[0].size () = = 0) {//M not exist} else {//find N * M = bigint[ 
 0]}


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.