题解 | #杨辉三角的变形#
杨辉三角的变形
https://www.nowcoder.com/practice/8ef655edf42d4e08b44be4d777edbf43
''' 1 2 3 4 5 6 7 8 9 1 3 5 7 9 11 13 15 17 l=[[None,1,None],[1,1,1]] print(l) ''' '''占用内存太大,报红 while True: try: n=int(input()) arr=[[0 for j in range(2*n)] for i in range(n)] # 创建n行空白二维列表 #print(arr) arr[0][n-1]=1 #print(arr[0]) for i in range(1,n): for j in range(n-i-1,n+i): arr[i][j]=arr[i-1][j-1]+arr[i-1][j]+arr[i-1][j+1] #print(arr[i]) if n<=2: print(-1) for j in range(2*n-1): if arr[n-1][j]%2!=0: continue else: print(j+1) break except: break ''' # 运行上述代码,可知从第3行开始,第一个偶数出现的位置循环:2 3 2 4 n=int(input()) if n==1 or n==2: print(-1) elif n%2==1: print(2) elif n%4==0: print(3) elif n%2==0 and n%4!=0: print(4)