正整数k的二进制倍数是正整数n,使得n只与基数为10的0s和1s编写,n是k的倍数。例如,111111是3的二进制倍数。
很容易证明一个正整数有无穷多个二进制倍数。有关每个这里的一个二进制倍数的构造证明,请参见k。乘以10的幂,你会得到无穷多的。
给定一个正整数k,返回k的最小二进制倍数。
正整数k。
一个正整数n,k最小的二进制倍数。
2 -> 10
3 -> 111
4 -> 100
5 -> 10
6 -> 1110
7 -> 1001
8 -> 1000
9 -> 111111111
10 -> 10
11 -> 11
12 -> 11100
13 -> 1001
14 -> 10010
15 -> 1110
16 -> 10000
17 -> 11101
18 -> 1111111110
19 -> 11001
20 -> 100
100 -> 100这是密码-高尔夫所以最短的提交字节,赢!如果你喜欢这个挑战,考虑一下.打高尔夫球也很开心!
这是RGS高尔夫表演的第一个挑战。如果你想参加比赛,你有96个小时的时间提交你的合格答案。记住,在奖品中有450个声誉!(见规则6)
否则,这仍然是一个常规的密码-高尔夫挑战,所以享受吧!
发布于 2020-02-24 09:47:46
发布于 2020-02-24 10:02:28
发布于 2020-02-24 09:46:55
`@YBUG\}HM` % Do...while
@ % Push iteration index (1-based)
YB % Convert to binary string (1 gvies '1', 2 gives '10, etc).
U % Convert string to number ('10' gives 10). This is the current
% solution candidate
G % Push input
\ % Modulo. Gives 0 if the current candidate is a multiple of the
% input, which will cause the loop to exit
} % Finally: execute on loop exit
H % Push 2
M % Push input to the second-last normal function (`U`); that is,
% the candidate that caused the loop to exit, in string form
% End (implicit). If top of the stack is 0: the loop exits.
% Otherwise: a new iteration is run
% Display (implicit)https://codegolf.stackexchange.com/questions/199995
复制相似问题