输入一个正整数,计算它的各位数字的阶乘之和,并判断它是否是一个阶乘和数。

会判定阶乘和数,但不会将阶乘输出在一起,求大佬帮写完整程序,因课程考核要求急需!!!跪谢!!!

 

样例输入形式:145

样例输出形式:145,5!+4!+1!=145

                         Yes

 

import math
 
n=int(input())
 
t=0
 
while n>0:
 
    t+=math.factorial(n%10)
 
    n//=10
 
i=1
 
while math.factorial(i)<t:
 
    i+=1
 
if math.factorial(i)==t:
 
    print('yes')
 
else:
 
    print('no')
 

 

# coding=utf-8
import math
n=int(input())
x=n
t=0

while n>0:
    i=n%10
    t+=math.factorial(n%10)

    print ("%d!+" %(i))

    n//=10
print ("=")
print (t)
if t==x:
    print('yes')
else:
    print('no')


#include <stdio.h>

#include <math.h>


int f(int n) {

  if (n == 1)

    return 1;

  else

    return n * f(n - 1);

}


int main(void) {


  int n, t, temp, sum = 0;

  scanf("%d", &n);

  printf("%d,", n);

  t = n;

  while (t >= 10) {

    temp = t / (int)pow(10, (int)log10(t));

    sum += f(temp);

    printf("%d!+", temp);

    t %= (int)pow(10, (int)log10(t));

  }

  sum += f(t);

  printf("%d!=%d\n", t, sum);

  printf("%s\n", sum == n ? "Yes" : "No");


  return 0;

}

 

def pf(n):
    if n==1:
        return 1
    return n*pf(n-1)

n = input().strip()
s = 0
li = []
for x in n[::-1]:
    x = int(x)
    s += pf(x)
    li.append(f'{x}!')
a = "+".join(li)
print(f'{n},{a}={s}')
if int(n)==s:
    print("Yes")
else:
    print("No")

 

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632

import math

n=int(input())

t=0

while n>0:

    t+=math.factorial(n%10)

    n//=10

i=1

while math.factorial(i)<t:

    i+=1

if math.factorial(i)==t:

    print('yes')

else:

    print('no')