Java丑数代码 解出来的1000悬赏!!!求大神

秋水之滨2022-10-04 11:39:541条回答

Java丑数代码 解出来的1000悬赏!!!求大神
Once upon a time in a strange situation, people called a number ugly if it was divisible by any of the
one-digit primes (2, 3, 5 or 7). Thus, 14 is ugly, but 13 is fine. 39 is ugly, but 121 is not. Note that 0 is
ugly. Also note that negative numbers can also be ugly: -14 and -39 are examples of such numbers.
One day on your free time, you are gazing at a string of digits, something like:
123456
You are amused by how many possibilities there are if you are allowed to insert plus or minus signs
between the digits. For example you can make:
1 + 234 - 5 + 6 = 236
which is ugly. Or
123 + 4 - 56 = 71
which is not ugly.
It is easy to count the number of different ways you can play with the digits: Between each two adjacent
digits you may choose put a plus sign, a minus sign, or nothing. Therefore, if you start with D digits
there are 3^(D-1) expressions you can make. Note that it is fine to have leading zeros for a number. If
the string is “0102”, then “01023”, “0+1-02+3” and “01-023” are legal expressions.
Your task is simple: Among the 3^(D-1) expressions, count how many of them evaluate to an ugly
number.
INPUT:
Each test case will be a single line containing a non-empty string of decimal digits. The string in each
test case will be non-empty and will contain only characters '0' through '9'. Each string is no more than
13 characters long.
OUTPUT:
Print out the number of expressions that evaluate to an ugly number for each test case, each one on a
new line.

已提交,审核后显示!提交回复

共1条回复
josephine121 共回答了29个问题 | 采纳率89.7%
有种奇怪的情况,如果一个数能被任何一位的质数(2,3,5或7)整除,那么这样的数就叫丑数。因此,14是丑数,但13是正常的,39是丑数,但121不是的。注意,0是丑数,同样负数也可能是丑数:-14和-39就是这样的数。

PS:大概意思一般做Java的应该都看得懂啊,我先翻译一段先,有空再翻,如果你够勤快的话,金山词霸也能看懂大概的意思。。。

手痒继续翻起,貌...
1年前

相关推荐