/************************************************************************/ /*题目:任意给定一个自然数N,寻找一个M,要求M是N的倍数,且它的所有各位数字 /* 都是1或者0组成,并要求M尽可能小。 /*例:N = 3 -->M = 3 * 37 = 111 N = 31 -->M = 31 * 3581 = 111011 /************************************************************************/ #include <iostream> using namespace std; int main() { int N; long M; long t; bool bFound = false; cout << "Please specilize a value to N: "; cin >> N; for (M = N * 2; !bFound; M++) { t = M; if (M % N == 0) { while (t)//逐位数字比较 { if (t % 10 != 1 && t % 10 != 0) break; t /= 10; if (t == 1) { bFound = true; cout << "M = " << N << " * " << M / N << " = " << M << endl; } } } } system("pause"); return 0; }