---
# System prepended metadata

title: Java_Cmoney_ft7208
tags: [Cmoney_Java題目]

---

---
tags: Cmoney_Java題目
---
Java_Cmoney_ft7208
===

![](https://i.imgur.com/uVWrFWN.png)
![](https://i.imgur.com/Y3vBCDi.png)



1.需要的 function
---
1.1 遞迴
---
這個 function 是回傳 beta 數量，隔天的 beta 數量是前一天的兩倍，
加上 Beta 的數量。

```java=
public static int f(int B, int day) {
        if (day <= 1)
            return B;
        return 2 * f(B, day - 1) + B;
    }
```



2.主程式
---
使用上面的 function 來看多少 Beta 多久會達到，題目中輸入的 beta

```java=
public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int B = sc.nextInt();
        int b = sc.nextInt();
        int count = 0;
        while(true){
            if (f(B,count) == b)
                break;
            count++;
        }
        System.out.println(count);
    }

```

3.完整程式
---
```java=
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int B = sc.nextInt();
        int b = sc.nextInt();
        int count = 0;
        while(true){
            if (f(B,count) == b)
                break;
            count++;
        }
        System.out.println(count);
    }

    public static int f(int B, int day) {
        if (day <= 1)
            return B;
        return 2 * f(B, day - 1) + B;
    }
}

```