题解 | #杨辉三角的变形#
杨辉三角的变形
https://www.nowcoder.com/practice/8ef655edf42d4e08b44be4d777edbf43
#include <iostream> using namespace std; int main() { int n; cin >> n; if(n <= 2){ cout << -1 << endl; return 0; } n = n - 3; n = n % 4; int ara[4] = {2,3,2,4}; cout << ara[n] << endl; return 0; } // 64 位输出请用 printf("%lld")
面对考察数学公式的题很难用一些数据结构粗暴求解,一般都是有一定的数学公式推导,如果没有推导就有一定的周期性,在此基础上在写代码。