2014-09-27 67 views
-5

乘以一個整數的數字和持續的過程給出了令人驚訝的結果是產品的序列總是到達一個數字。例如: 71535155 88 64248 27 144 的必要達到單個位的數字產品的數目稱爲的 該整數持久性數。因此,715和88有3持續數,而27持續2 做一個程序,找出具有持久性大於3的唯一兩位數字? 這就是問題所在。Python的持久性名錄

for i in range(10,100): 
    for l in range(i): 
     numbers = list(str(l)) 
     num = int(numbers[0]) * int(numbers[1]) 

這就是我所擁有的。請幫忙

回答

0

大家都認爲這是一個不好的問題,所以我覺得不好回答,並幫助你作弊:( ,但它很有趣!:)和解決的東西是一個標誌,你很聰明,嘿,和不是真正的嘗試是相反的標誌。

def newn(n): 
    numbers = [int(c) for c in str(n)] 
    new = 1 
    for i in numbers: 
     new *= i 
    digits = len(str(new)) 
    return new, digits 

for n in xrange(99,9,-1): 
    if persistence > 3: 
     print 'persistence %i, number %i' % (persistence, n + 1) 
     break 

    digits, persistence = 2, 0 
    while digits != 1: 
     persistence += 1 
     n, digits = newn(n) 
0

答案是77,都到49,都到36,都到18都到8

def multiply_digits(x): 
    total = 1 
    for digit in str(x): 
     total *= int(digit) 
    return total 

for value in range(11, 100): 
    new_value = multiply_digits(value) 
    persistance = 1 
    while new_value >= 10: 
     new_value = multiply_digits(new_value) 
     persistance += 1 
     if persistance > 3: 
      print value