본문 바로가기
코딩테스트/백준

JAVA 백준 3733번 Shares

by 광고(주) 2022. 7. 29.
반응형

문제

A group of N persons and the ACM Chief Judge share equally a number of S shares (not necessary all of them). Let x be the number of shares aquired by each person (x must be an integer). The problem is to compute the maximum value of x.

Write a program that reads pairs of integer numbers from an input text file. Each pair contains the values of 1 ≤ N ≤ 10000 and 1 ≤ S ≤ 109 in that order. The input data are separated freely by white spaces, are correct, and terminate with an end of file. For each pair of numbers the program computes the maximum value of x and prints that value on the standard output from the beginning of a line, as shown in the example below.

예제 입력 1 

1 100
2 7
10 9
10 10

예제 출력 1 

50
2
0
0

알고리즘 분류

사칙연산(arithmetic), 수학(math)

소스코드

import java.io.IOException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int N = sc.nextInt();
            int S = sc.nextInt();
            System.out.println(S / (N + 1));
        }
    }
}
반응형

댓글