按 0/1 多重格式化
可能的重复:
查找满足以下条件的数字的倍数可以写成1和0
给定数字 n (2 <= n <= 1000),找到以 10 为基数写成的最小非零倍数,其中数字为 0 和仅 1 个。示例: 2 -> 10、 3→ 111、4→ 100, 7 -> 100, 7 -> 1001, 11 -> 11 11、9→ 111 111 111。
我想,遵循剩余的由数字n组成的数字除法,其格式为0/1。感谢您的帮助!
{10/3= 3 remaining 1 -> and the finaly is 111 !!!
10/4= 4 ramining 2 -> and the finaly is 100 !!!
10/6= 1 ramainin 4 -> and the finaly is 1110 !!!
I don't understand is the logic}
Possible Duplicate:
Find multiple of a number that can be written with 1s and 0s
Given the number n (2 <= n <= 1000), find the lowest nonzero multiple of which is written in base 10 with digits 0 and 1 only. Examples: 2 -> 10, 3 -> 111, 4 -> 100, 7 -> 1001, 11 -> 11, 9 -> 111 111 111.
I think, follow the remaining division of numbers consist of numbers n which is formatted 0/1.Thanks for your help!
{10/3= 3 remaining 1 -> and the finaly is 111 !!!
10/4= 4 ramining 2 -> and the finaly is 100 !!!
10/6= 1 ramainin 4 -> and the finaly is 1110 !!!
I don't understand is the logic}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题基本上是说:找到仅由 1 和 0 组成的 n 的第一个非零倍数。我们这里讨论的不是二进制(基数为 2)或余数或任何奇特的东西。以下是一些示例,格式如下:
您需要找出一种算法才能使其发挥作用!您可以使用蛮力:
我在 C# 中实现了这个来测试它,它为我提供了 2 到 10 之间的 n 的以下输出:
可能有更快的实现,但这应该让您知道在哪里开始。
The question is basically saying: Find the first non-zero multiple of n that consists of only 1s and 0s. And we're not talking binary (base 2) or remainders or anything fancy here. Here are some examples, in the format:
You need to figure out an algorithm to make it work! You could use brute force:
I implemented this in C# to test it and it gave me the following output for n between 2 and 10:
There are probably faster implementations, but this should give you an idea of where to start.
如果您寻求帮助解释(家庭作业)问题,我认为这意味着:“对于给定的数字,找出仅包含数字 1 或 0 的最小倍数”
因此,例如,如果数字是2:
执行此操作的非暴力方法是迭代仅包含 0 和 1 的数字,然后确定该数字是否是相关数字的倍数。这种方法比迭代
n
的倍数并确定它是否仅包含0
和1
更有效。获取仅包含
0
和1
的数字列表的一种简单方法是迭代整数,并针对每个值,将其二进制表示形式解释为十进制数。这里有一个在线演示可以帮助您入门: http://jsfiddle.net/6j5De/4/
这可能是家庭作业,我会让你把它翻译成你的主题语言。
If you're asking for help interpreting the (homework) question, here's what I think it means: "For a given number, find out lowest multiple of it that contains only digits 1 or 0"
So, for example, if the number is 2:
The non-bruteforce way to do this would be to iterate throught numbers that contain only 0 and 1 then figure out if the number is a multiple of the number in question. This approach will be substantially more efficient than iterating through the multiples of
n
and determining if it contains only0
and1
.An easy way to get a list of numbers that contain only
0
and1
would be iterate throught the integers and for each value, interpret its binary representation as a decimal number.Here's an online demo to get you started: http://jsfiddle.net/6j5De/4/
Since it's likely to be homework, I'll leave it up to you to translate that to your subject language.