给出一个数字n,需要不断地将所有数位上的值做乘法运算,直至最后数字不发生变化为止。
问最后生成的数字为多少?
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # @param n long长整型 老师给牛牛的数字 # @return int整型 # def calcu(x): n_fix = [] if x < 10: return x else: while x > 0: n_fix.append(x%10) x = math.floor(x/10) out = 1 for items in n_fix: out *= items return out import math class Solution: def mathexp(self , n ): # write code here result = calcu(n) while result >= 10: result = calcu(result) return result
class Solution: def mathexp(self , n ): # write code here num = [] multi = n if n<10: return n while multi>=10: n = multi multi = 1 num = [] if n<10: return n while n: num.append(n%10) n = int(n/10) if 0 in num: return 0 else: for i in range(0,len(num)): multi *= num[i] return multi
func mathexp(n int64)int { var single int64 =0 var res int64=1 if n<10{ return int(n) } for n>=1{ single=n%10 n=n/10 res = single*res } return mathexp(res) }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param n long长整型 老师给牛牛的数字 * @return int整型 */ public int mathexp (long n) { // write code here long t = 1; long m = n; while(m>=10){ char[] c = String.valueOf(m).toCharArray(); for(int i=0; i<c.length; i++){ t*= Integer.parseInt(String.valueOf(c[i])); } m = t; t = 1; } return (int)m; } }