# day1 py蓝桥杯打卡

.

``````
import math
def gbs(a,b):
return a*b//math.gcd(a,b)
a=[0]*2022
for i in range(1,2021):
for j in range(i+1,i+22):
if j>2021:
break
if a[j]==0:
a[j]=a[i]+gbs(i,j)
else:
a[j]=min(a[j],a[i]+gbs(i,j))
print(a[2021])``````

``````N = int(input())
list1 = [] #保存杨辉三角
list = [1]
count = 0
for n in range(1000):
row = [1]  #保存行
list1.append(row)
if n == 0:
row.append(1)
continue
for m in range(1,n):
row.append(list1[n - 1][m - 1] + list1[n - 1][m])
row.append(1)
for i in row:
list.append(i)

for i in list:
if i == N:
print(count + 1)
break
else:
count = count + 1``````

``````n = int(input())
res = 0
state = [-1] * n

def check(r, c):
for i in range(r): # 不能出现在同一列或者对角线
if state[i] == c or (abs(r - i) == abs(c - state[i]) and r - i < 3):
return False
return True

def dfs(row):
global res

if row == n:
res += 1
return

for column in range(n):
if check(row, column):
state[row] = column
dfs(row + 1)
state[row] = -1

dfs(0)
print(res)``````

...全文
18 回复 打赏 收藏 转发到动态 举报

30,346

• 近7日
• 近30日
• 至今