引用的思路是题解场另一大佬的思路原链接
#include<stdio.h>
//杨辉三角规律 行号 第一个偶数在该行第几个
// 1 1 -1
// 1 1 1 2 -1
// 1 2 3 2 1 3 2
// 1 3 6 7 6 3 1 4 3
// 1 4 10 16 19 16 10 4 1 5 2
// 1 5 15 30 45 51 45 30 15 5 1 6 4
// 1 6 21 40 80 126 141 126 80 40 21 6 1 7 2
// 首个偶数在该行第几个的规律: -1 -1 (2 3 2 4)···(2 3 2 4)
int main(int argc, char const *argv[])
{
int num = 0;
int str[4] = {2, 3, 2, 4};
printf("%d\n", 3%2);
while (scanf("%d", &num) != EOF)
{
if (num <= 2)
{
printf("-1\n");
return 0;
}
//因为是从第三行开始进入循环,
printf("%d\n", str[ (num+1) % 4] );
}
return 0;
}

京公网安备 11010502036488号