神奇的细胞(Java版)

版权声明:版权问题请加微信:17165380098 备注 版权问题 https://blog.csdn.net/qq_30277453/article/details/82846010

Problem Description

我啸在杭州回来后,带回来一个神奇的细胞。

一开始只有一个细胞,每一小时分裂一次(细胞不会死亡,神奇的细胞),也就是说在第一个小时的时候只有一个细胞,第二个小时有两个细胞,第三个小时有四个细胞.....一直分裂下去,问当第n个小时的时候有多少细胞?

Input

单组输入,每组输入只有一个整数n(1<=n<=20)。

Output

输出一行,一个整数,即第n个小时的时候的细胞数量。

Sample Input

5

Sample Output

16
import java.util.Scanner;
public class Main{
    static long f[] = new long[10010];
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
       f[1]=1;
       f[2]=2;
       f[3]=4;
       f[n]=(long)(Math.pow(2,n-1));/*pow函数得到的数是float型,需要强制类型格式转换*/
            System.out.println(f[n]);
        }
        }

猜你喜欢

转载自blog.csdn.net/qq_30277453/article/details/82846010