문제 설명

가로 N cm, 세로 M cm의 직사각형 종이로 A4 용지를 최대 몇 개를 만들 수 있는지 구해주세요.
여기서 말하는 A4용지의 규격은 편의상 가로 20cm, 세로 40cm의 수치를 가집니다.




제한사항

Input Format

  • 첫째 줄에 정수N과 M이 공백으로 구분되어 주어집니다.
    (단, 1 ≤ N ≤ 2,000,000,000)

Output Format

  • 주어진 종이로 만들 수 있는 A4용지의 최대 개수를 출력합니다.

Others

  • 제한시간 : 5초




입출력 예

Sample Input

50 60

Sample Output

3




Sample Input

4429 3893

Sample Output

21437

Idea

직사각형의 종이의 가로,세로 값을 바꿔가면서 잘라야 하는 a4용지에 대입해보면 갯수가 몇개인지 알 수 있다.
만약 아래와 같이 코딩을 하였다면, 1개의 테스트케이스를 통과하지 못하게 됩니다. ```python width, height = map(int, input().split()) a4_width = 20 a4_height = 40 tempRow = height // a4_width tempCol = width // a4_height temp = (height // a4_width) * (width // a4_height) tempRow = height // a4_height tempCol = width // a4_width temp1 = (height // a4_height) * (width // a4_width) print(max(temp, temp1)) ``` 통계학에서 포함-배제라는 개념이 있는데, 이 개념으로 접근해야지만 정답입니다.
자세한 설명은 아래의 Reference를 참고해 주세요!




Code

width, height = map(int, input().split())

a4_width = 20
a4_height = 40

tempRow = height // a4_width
tempCol = width // a4_height
temp = (height // a4_width) * (width // a4_height)

tempRow = height // a4_height
tempCol = width // a4_width
temp1 = (height // a4_height) * (width // a4_width)

result = 2 * (width // a4_height) * (height // a4_height)
print(temp + temp1 - result)

Explain

생략




References

댓글남기기