问题描述

小F最近迷上了玩一款游戏,她面前有一个永久代币卡的购买机会。该卡片的价格为 a 勾玉,每天登录游戏可以返还 b 勾玉。小F想知道她至少需要登录多少天,才能让购买的永久代币卡回本。
测试样例

样例1:

输入:a = 10, b = 1
输出:10

样例2:

输入:a = 10, b = 2
输出:5

样例3:

输入:a = 10, b = 3
输出:4

代码

public class Main {
public static int solution(int a, int b) {
// 计算需要的天数
double days = (double) a / b;
// 向上取整
int result = (int) Math.ceil(days);
return result;
}

public static void main(String[] args) {
    System.out.println(solution(10, 1) == 10);
    System.out.println(solution(10, 2) == 5);
    System.out.println(solution(10, 3) == 4);
}

}

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐