按 0/1 多重格式化

发布于 2024-12-11 23:03:09 字数 643 浏览 0 评论 0原文

可能的重复:
查找满足以下条件的数字的倍数可以写成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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冬天旳寂寞 2024-12-18 23:03:09

问题基本上是说:找到仅由 1 和 0 组成的 n 的第一个非零倍数。我们这里讨论的不是二进制(基数为 2)或余数或任何奇特的东西。以下是一些示例,格式如下:

 n => The first multiple of n with only 1s and 0s is x (n * y = x)
 --------------------------------------------------------------------------
 2 => (2 x 5 = 10)
 3 => (3 x 37 = 111)
 4 => (4 x 25 = 100)
 7 => (7 x 143 = 1001)
11 => (11 x 1 = 11)
 9 => (9 x 12,345,679 = 111,111,111)

您需要找出一种算法才能使其发挥作用!您可以使用蛮力:

for each n between 2 and 1000
    y = 1
    x = 0
    do
        x = n * y++
    while (x is not 0 and string(x) is not all 0s and 1s)
    print n => x
next n

我在 C# 中实现了这个来测试它,它为我提供了 2 到 10 之间的 n 的以下输出:

2 => 10
3 => 111
4 => 100
5 => 10
6 => 1110
7 => 1001
8 => 1000
9 => 111111111
10 => 10

可能有更快的实现,但这应该让您知道在哪里开始。

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:

 n => The first multiple of n with only 1s and 0s is x (n * y = x)
 --------------------------------------------------------------------------
 2 => (2 x 5 = 10)
 3 => (3 x 37 = 111)
 4 => (4 x 25 = 100)
 7 => (7 x 143 = 1001)
11 => (11 x 1 = 11)
 9 => (9 x 12,345,679 = 111,111,111)

You need to figure out an algorithm to make it work! You could use brute force:

for each n between 2 and 1000
    y = 1
    x = 0
    do
        x = n * y++
    while (x is not 0 and string(x) is not all 0s and 1s)
    print n => x
next n

I implemented this in C# to test it and it gave me the following output for n between 2 and 10:

2 => 10
3 => 111
4 => 100
5 => 10
6 => 1110
7 => 1001
8 => 1000
9 => 111111111
10 => 10

There are probably faster implementations, but this should give you an idea of where to start.

飘逸的'云 2024-12-18 23:03:09

如果您寻求帮助解释(家庭作业)问题,我认为这意味着:“对于给定的数字,找出仅包含数字 1 或 0 的最小倍数”

因此,例如,如果数字是2:

Multiples of 2 = {2, 4, 6, 8, 10, 12, 14, .... }
                               |
                               |
                       this is your answer!                  

执行此操作的非暴力方法是迭代仅包含 0 和 1 的数字,然后确定该数字是否是相关数字的倍数。这种方法比迭代 n 的倍数并确定它是否仅包含 01 更有效。

获取仅包含 01 的数字列表的一种简单方法是迭代整数,并针对每个值,将其二进制表示形式解释为十进制数。

这里有一个在线演示可以帮助您入门: 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:

Multiples of 2 = {2, 4, 6, 8, 10, 12, 14, .... }
                               |
                               |
                       this is your answer!                  

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 only 0 and 1.

An easy way to get a list of numbers that contain only 0 and 1 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文