python立方尾不变
方法一
最普通的方法:
示例代码如下:
count=0
N=int(input())
for x in range(1,N+1):
if(x==1):
print("1",end=" ")
count+=1
elif(x<10 and x>1):
if((x**3)%10==x):
print(x,end=" ")
count+=1
elif(x>=10 and x<100 and (x**3)%100==x):
print(x,end=" ")
count+=1
elif(x>=100 and x<1000 and (x**3)%1000==x):
print(x,end=" ")
count+=1
elif(x>=1000 and x<=10000):
if((x**3)%10000==x):
print(x,end=" ")
count+=1
print()
print(count)
方法二
示例代码如下:
N=input()
for x in range(1,len(N+1)):
num=str(x**3)
if(num.endswitch(str(x))): #endswitch方法判断字符串是否以指定字符或子字符串结尾。
print(x,end=" ")
count+=1
print()
print(count)