题解 | #杨辉三角的变形#

杨辉三角的变形

https://www.nowcoder.com/practice/8ef655edf42d4e08b44be4d777edbf43

#include <iostream>
#include <bits/stdc++.h>
#include <vector>
using namespace std;

int main() {
    //用一个vector<vector<int>> nums把整个杨辉三角记录下来的方法在n=10000的测试用例中内存超限
    //我们再想想巧一些的方法
    //我们发现,除去n==1和n==2,其余的n为奇数时都输出2,n为偶数时如果能被4整数,就返回3,否则返回4
    int n;
    cin>>n;
    if(n==1||n==2){
        cout<<-1<<endl;
    }
    else if(n%2==1) cout<<2<<endl;
    else if(n%4==0) cout<<3<<endl;
    else 
    cout<<4<<endl;

}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务