题解 | 杨辉三角的变形

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        int n = in.nextInt();

        // 找规律

        //n: 1  2 3 4 5 6 7 8 9 10 11 12

        //  -1 -1 2 3 2 4 2 3 2 4  2  3

        if (n < 3) {

            System.out.print(-1);

        } else {

            if (n % 2 != 0) {

                System.out.print(2);

            } else if (n % 4 == 0) {

                System.out.print(3);

            } else {

                System.out.print(4);

            }

        }

    }

}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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