Subscribed unsubscribe Subscribe Subscribe

yukicoder No.128 お年玉(1)

Problem

No.128 お年玉(1) - yukicoder

Code

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.System.in;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        long N = Long.parseLong(reader.readLine());
        long M = Long.parseLong(reader.readLine());
        findMaximunOtosidama(N, M);
    }

    private static void findMaximunOtosidama(long N, long M) {
        long lo = 1;
        long hi = (Long.MAX_VALUE-1)/M;
        while (lo < hi) {
            long mid = lo + (hi - lo + 1) / 2;
            if (isFeasible(N, M, mid)) {
                lo = mid;
            } else {
                hi = mid - 1;
            }
        }
        System.out.println((lo/1000)*1000);
    }

    private static boolean isFeasible(long N, long M, long money) {
        return money * M <= N;
    }

}
Remove all ads