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]}