第一次见 杨辉三角+re 记录一下没完全理解
v2 = sub_80486CD((int)&unk_8049BE0);
if ( (unsigned __int8)sub_8048783((int)&unk_8049BE0, v2) != 1 )
signed int __cdecl sub_80486CD(int a1) { int j; // [sp+0h] [bp-14h]@4 int v3; // [sp+4h] [bp-10h]@4 int i; // [sp+8h] [bp-Ch]@1 int v5; // [sp+Ch] [bp-8h]@1 v5 = 0; for ( i = 0; i <= 1024 && *(_DWORD *)(4 * i + a1); i = v5 * (v5 + 1) / 2 ) { v3 = 0; for ( j = 0; j <= v5; ++j ) v3 += *(_DWORD *)(4 * (j + i) + a1); if ( 1 << v5 != v3 ) return -1; ++v5; } return v5; }
翻译一下是
v5=0; for(int i =0;i<=1024 && a[i];i=v5*(v5+1)/2) { v3=0; for(j=0;j<=v5;++j) v3+=a[i+j]; if(1<<v5 != v3) return -1; ++v5; }
注意: *(_DWORD *)(4 * i + a1)=a[i]
*(_DWORD *)(4 * (j + i) + a1)=a[i+j]
1<<v5等于2的v5次方
可得,v5=0,1,2,3,4,5,6,7,8,9
i=0,1,3,6,10,15,21,28,36
v5=0时:v3=a[0]
v5=1时:v3=a[1]+a[2]
v5=2时:v3=a[3]+a[4]+a[5]
...
signed int __cdecl sub_8048783(int a1, signed int a2) { int v3; // [sp+10h] [bp-10h]@2 int v4; // [sp+14h] [bp-Ch]@2 signed int i; // [sp+18h] [bp-8h]@1 int v6; // [sp+1Ch] [bp-4h]@1 v6 = 0; for ( i = 1; i < a2; ++i ) { v4 = 0; v3 = i - 1; if ( !*(_DWORD *)(4 * i + a1) ) return 0; while ( a2 - 1 > v3 ) { v4 += *(_DWORD *)(4 * (v3 * (v3 + 1) / 2 + v6) + a1); ++v3; } if ( *(_DWORD *)(4 * (v3 * (v3 + 1) / 2 + i) + a1) != v4 ) return 0; ++v6; } return 1; }
翻译
int v6 =0; for(int i=1;i<a2;++i){ v4=0; v3=i-1; if(!a[i]) return 0; while(a2-1>v3){ v4+=a1[v3*(v3+1)/2+v6]; ++v3; } if(a1[v3*(v3+1)/2+i]!=v4) return 0; ++v6; } return 1;
注意:*(_DWORD *)(4 * i + a1)=a[i]
*(_DWORD *)(4 * (v3 * (v3 + 1) / 2 + v6) + a1)=a1[v3*(v3+1)/2+v6]
*(_DWORD *)(4 * (v3 * (v3 + 1) / 2 + i) + a1)=a1[v3*(v3+1)/2+i]
.第n行数字的和为2(n-1)。1=2(1-1),1+1=2(2-1),1+2+1=2(3-1),1+3+3+1=2(4-1),1+4+6+4+1=2(5-1),1+5+10+10+5+1=2(6-1)对应的第一条嘛
第二条没看出来看别人wp可知.斜线上数字的和等于其向左(从左上方到右下方的斜线)或向右拐弯(从右上方到左下方的斜线),拐角上的数字。1+1=2,1+1+1=3,1+1+1+1=4,1+2=3,1+2+3=6,1+2+3+4=10,1+3=4,1+3+6=10,1+4=5
是杨辉三角
def generate_pascals_triangle(n): # 初始化杨辉三角的二维列表 a = [[0] * (n + 1) for _ in range(n + 1)] # 填充杨辉三角的第一列 for i in range(1, n + 1): a[i][1] = 1 # 填充杨辉三角的其余部分 for i in range(2, n + 1): for j in range(1, i + 1): a[i][j] = a[i - 1][j - 1] + a[i - 1][j] return a def print_pascals_triangle(a): result = [] for i in range(1, len(a)): for j in range(1, i + 1): result.append(str(a[i][j])) print(''.join(result)) def main(): n = 20 a = generate_pascals_triangle(n) print_pascals_triangle(a) if __name__ == "__main__": main()
1111211331146411510105116152015611721353521711828567056288119368412612684369111045120210252210120451011115516533046246233016555111112662204957929247924952206612111378286715128717161716128771528678131114913641001200230033432300320021001364911411151054551365300350056435643550053003136545510515111612056018204368800811440128701144080084368182056012016111713668023806188123761944824310243101944812376618823806801361711181538163060856818564318244375848620437583182418564856830608161531811191719693876116282713250388755829237892378755825038827132116283876969171191
RCTF{37894beff1c632010dd6d524aa9604db}