我有一个问题,如果有人能帮助我,我将非常感谢你。 我应该写一个程序来找到下一个Curzon号码,一个给定的号码N被称为Curzon号码 的
2^N + 1 is divisible by 2*N + 1.
读入一个号码,然后找到下一个Curzon号码! 我想出了这个,但它不起作用我真的不知道下一步
number = int(input("Write a number ")
num1 = 2** number +1
num2 = 2* number +1
if num1%num2==0:
print()
else:
print()
测试用例示例:
input:
4
output:
5
解释
check 5
2 ^ 5 + 1 = 33
2 * 5 + 1 = 11
33是11的倍数-->;5是下一个Curzon号码
写一个简单的方法来检查vlaue是否是curzon数字
然后递增
number
,直到它为一@Azro的解决方案较小,但您应该会发现这一个更容易理解
我只是把你的代码放在一个循环中,这样我就可以增加
number
,直到找到下一个Curzon号码相关问题 更多 >
编程相关推荐