Simple Number Finding
You are playing a card game with your friends. This game in China named “扎金花”. In this game, the
2, 3, 5 are some simple powerful numbers. Because the combination of 2,3,5 is less than any other combinations
but greater than the AAA, which is the king in this game. In today, you want to find if a number is a simple
number, in which their factors only include 2, 3 and 5.
So your task is to find out whether a given number is an amazing number.
E.g
Input: 6
Output: (2, 3)
Explanation: 6 = 2 x 3Input: 8
Output: (2, 2, 2)
Explanation: 8 = 2 x 2 x 2
Input: 14
Output:None
Explanation: 14 is not amazing since it includes another prime factor 7.
How to check your answer:
If you test 1845281250, your program should give (2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5)
If you test 3690562500, your program should give (2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5);
If you test 1230187500, your program should give (2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5);
If you test 10023750, your program should give None
import numpy as np
divNum = np.array([1, 2, 3, 5], dtype=int)
numList = []
def main():
################### At here input your number################
inputNum = 1845281250
################### At here input your number################
while True:
if inputNum % 2 == 0:
inputNum = inputNum / 2
numList.append(2)
elif inputNum % 3 == 0:
inputNum = inputNum / 3
numList.append(3)
elif inputNum % 5 == 0:
inputNum = inputNum / 5
numList.append(5)
else:
if (divNum == inputNum).any():
if inputNum != 1:
numList.append(inputNum)
print(numList)
else:
print('None')
break;
if __name__ == '__main__':
main()
本文介绍了一种名为“扎金花”的中国纸牌游戏中神奇数的概念,即仅由2、3、5这三个质数组成的数。通过分析和算法实现,我们探讨了如何判断一个数是否为神奇数,并提供了具体的代码示例。
2万+

被折叠的 条评论
为什么被折叠?



