Prime factorization of a factorial

后端 未结 6 1423
陌清茗
陌清茗 2021-01-05 17:38

I need to write a program to input a number and output its factorial\'s prime factorization in the form:

4!=(2^3)*(3^1)

5!=(2^3)*(3^1)*(5^1)
6条回答
  •  悲&欢浪女
    2021-01-05 17:55

    If you write out the factorial 5!:
    1 * 2 * 3 * 4 * 5,
    you will notice that there is one non-prime number: 4. 4 can be written as 2 * 2 or 2^2, which is where the extra 2s come from. Add up all of the occurrences (exponential forms are in parentheses; add exponents for like bases):
    2 (2^1) * 3 (3^1) * 4 (2^2) * 5 (5^1), you get the proper answer.

提交回复
热议问题