Classrooms and Calculators

시간 제한1초메모리 제한2048 MB

요약
세 친구가 각각 0일과 d_i일 간격의 배수일마다 못 노는 상황에서, n일을 채우고 캠페인을 끝내는 날짜를 구한다.
난이도

보통10점 중 5점

유형
수학, 정수론, 이분 탐색
정답자
아직 제출이 없습니다

문제

You're trying to organize a group of yourself and 33 friends to play a campaign of your favorite tabletop game, Classrooms & Calculators. Your schedule is free every day, but your friends all have some scheduling conflicts. Let today be day 00, tomorrow be day 11, etc. Your first friend can't play today or every d_1d\_1 days after today, your second friend can't play today or every d_2d\_2 days after today, and your third friend can't play today or every d_3d\_3 days after today. You can only play on a day if nobody has a conflict, and you always play on days with no conflicts. For example, if d_1=3d\_1 = 3, d_2=4d\_2 = 4, and d_3=5d\_3 = 5, in the first 1010 days you would play on days 11, 22, and 77, but not on days 00, 33, 44, 55, 66, 88, 99, and 1010.

Your campaign's Classroom Teacher has told you that it will take nn days of playing to complete the campaign; can you determine the number of the day you finish the campaign?

입력

The first line of the input contains the values of d_1,d_2d\_1, d\_2, and d_3d\_3 (each between 22 and 5050, inclusive), each separated by a single space, describing your friends' schedule conflicts. The second line contains nn, the number of days you will need to play on to complete the campaign (1≤n≤5⋅108)(1 \le n \le 5\cdot10^8).

You are guaranteed that the values of d_1d\_1, d_2d\_2, and d_3d\_3 are such that you can complete the campaign in finite time.

출력

You should output a single number, the number of the day on which you finish the campaign.

예제2

  1. 예제 1

    입력
    5 7 9
    1
    
    예상 출력
    1
    
  2. 예제 2

    입력
    2 3 4
    7
    
    예상 출력
    19