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

Onceuponatimeinastrangesituation,peoplecalledanumberuglyifitwasdivisiblebyanyoftheone-digitprimes(2,3,5or7).Thus,14isugly,but13isfine.39isugly,but121isnot.Notethat0isugly...

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.

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值