n=int(input())
ls=[int(i) for i in input().split()]
ls.sort()
print(ls[0])
n,m=map(int,input().split())
x,y,a,b=0,0,0,0
for i in range(1,n+1):
if i%m==0:
y+=1
b+=i
else:
x+=1
a+=i
print("{:.1f} {:.1f}".format(b/y,a/x))
n=int(input())
if n==1:
print(1)
else:
x=0
while True:
x+=1
n//=2
if n==1:
break
print(x+1)
n=int(input())
m=int((1+n)*n/2)
x=n
for i in range(1,m+1):
print("{:02d}".format(i),end="")
if i==n:
print("")
x-=1
n+=x
from math import factorial
n=int(input())
sum=0
for i in range(1,n+1):
sum+=factorial(i)
print(sum)
m,n=map(int,input().split())
n=str(n)
count=0
for i in range(1,m+1):
j=str(i)
for k in j:
if k==n:
count+=1
print(count)
he,tongji=0,1
n=int(input())
while True:
he+=1/tongji
tongji+=1
if he>n:
break
print(tongji-1)
k=int(input())
count=0
x,y=0,0
for i in range(1,k+1):
if i>x:
y+=1
x+=y
count+=y
else:
count+=y
print(count)
k=int(input())
print(int((1+k)*k/2))
from math import sqrt
def hanshu(n):
for i in range(2,int(sqrt(n))+1):
if n%i==0:
return False
return True
n=int(input())
x,count1,count2=1,0,0
while True:
x+=1
y=hanshu(x)
if y==True and count1+x<=n:
count2+=1
count1+=x
print(x)
if count1+x>n:
break
print(count2)
代码一:
from math import sqrt
def hanshu(x,y,z):
global ls,n,m
if y==x:
for i in ["1","3","5","7","9"]:
z+=i
hanshu(x,y-1,z)
z=z[:-1]
elif y==0:
j=int(z[1:][::-1]+z)
if j>=n and j<=m and zhishuhanshu(j)==True:
ls.append(j)
else:
for i in ["0","1","2","3","4","5","6","7","8","9"]:
z=i+z
hanshu(x,y-1,z)
z=z[1:]
def huiwenhanshu1(x):
x=x//2+1
hanshu(x,x,"")
def zhishuhanshu(n):
m=int(sqrt(n))+1
for i in range(2,m):
if n%i==0:
return False
return True
n,m=map(int,input().split())
x,y,ls=len(str(n)),len(str(m)),[]
for i in range(x,y+1):
if i%2==1:
huiwenhanshu1(i)
else:
if i==2:
if 11>=n and 11<=m:
ls.append(11)
ls.sort()
for i in ls:
print(i)
注释:使用递归创建回文数字,然后暴力判断素数,完全通过
代码二:
from math import sqrt
def hanshu(a,b):
ls=[True]*(b+1)
c=int(sqrt(b))+1
d=2
while d<c:
if ls[d]==True:
for i in range(d+d,b+1,d):
ls[i]=False
d+=1
for i in range(a,b+1):
j=str(i)
if j==j[::-1]:
if ls[i]==True:
print(j)
a,b=map(int,input().split())
hanshu(a,b)
注释:欧拉筛法找出所有素数,然后判断是否回文。不能通过。因为基数太大。
x=0
y=float(input())
a=0
while True:
x+=1
a+=2*pow(0.98,x-1)
if a>=y:
break
print(x)
x=int(input())
if x>0:
print(int(str(x)[::-1]))
elif x==0:
print(0)
else:
print(-int(str(x)[1:][::-1]))
n=int(input())
if n==0:
print("0.00")
elif n==1 or n==2:
print("1.00")
else:
a,b,c=1,1,2
while c<n:
d=a+b
a=b
b=d
c+=1
print("{:.2f}".format(b))
n=int(input())
ls=[int(i) for i in input().split()]
print(max(ls)-min(ls))
def hanshu(ls):
x=len(ls)
y=0
z=1
for i in range(x-1):
if ls[i]+1==ls[i+1]:
z+=1
else:
if z>y:
y=z
z=1
else:
z=1
else:
if z>y:
y=z
print("{}\n".format(y))
n=int(input())
ls=[int(i) for i in input().split()]
hanshu(ls)
from math import sqrt
def hanshu(n):
ls,x,y=[True]*(n+1),2,int(sqrt(n))+1
while x<=y:
for i in range(x*2,n+1,x):
ls[i]=False
x+=1
ls=[i for i in range(2,n) if ls[i]==True]
return ls
n=int(input())
ls=hanshu(100000)
for i in ls:
if n%i==0:
j=n/i
print("{:.0f}".format(max(i,j)))
break
注释:使用欧拉筛法
n=int(input())
for i in range(n):
for j in range(n):
if j==n-1:
print("{:02d}".format(n*i+j+1))
else:
print("{:02d}".format(n*i+j+1),end="")
print("")
m=(n+1)*n//2
ls=[i for i in range(1,m+1)]
z=0
for i in range(1,n+1):
for j in range(1,n+1):
if i<=n-j:
print(" ",end="")
elif j==n:
print("{:02d}".format(ls[z]))
z+=1
else:
print("{:02d}".format(ls[z]),end="")
z+=1
n=int(input())
ls=[int(i) for i in input().split()]
ls.sort()
m=sum(ls[1:-1])
print("{:.2f}".format(m/(n-2)))
n=int(input())
n//=52
k=1
while True:
if (n-21*k)%7==0 and (n-21*k)//7<=100:
print((n-21*k)//7)
print(k)
break
k+=1
ls=[]
for i in range(12):
j=int(input())
ls.append(j)
x,y,z=0,0,0
for i in ls:
x+=300
x-=i
y+=1
if x<0:
print(-y)
break
else:
z+=100*(x//100)
x-=100*(x//100)
else:
print(int(x+z*1.2))