题解 | #杨辉三角的变形#
杨辉三角的变形
https://www.nowcoder.com/practice/8ef655edf42d4e08b44be4d777edbf43
#include<iostream> #include<vector> using namespace std; int FindIndex(int n) { if(n<=2) cout<<-1<<endl; else if(n%4==1||n%4==3) cout<<2<<endl; else if(n%4==2) cout<<4<<endl; else cout<<3<<endl; return 0; } int main() { int n; while(cin>>n) { int res=FindIndex(n); //cout<<res<<endl; } return 0; }
int FindIndex(int n) { int Index[]={4,2,3,2}; int res=-1; if(n>2) res = Index[(n-2)%4]; cout<<res<<endl; return 0; }