题解 | #大吉大利,今晚吃鸡#

大吉大利,今晚吃鸡

https://www.nowcoder.com/practice/c9d9f9c60b4448eabc0569f80a3461bb

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int n = in.nextInt();
            int total = f(n);
            System.out.println(total);
        }
    }
  //手工找到规律——>每个数等于前面的数*3+2
    public static int f(int n) {
        int total = 0;
        for (int i = 0; i < n; i++) {
            total = (total * 3) + 2;
        }
        return total;
    }
}

全部评论

相关推荐

昨天 10:44
青岛工学院 Java
机械打工仔:对方没做错任何事,你自己在这自找没趣呢,就算他工资不高,人家定多少薪资是人家的事,况且人家写了1~3年清清楚楚
点赞 评论 收藏
分享
06-05 19:46
已编辑
武汉大学 后端
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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