Algorithm
Problem Name: 2 AD-HOC - beecrowd | 1708
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1708
Lap
By Vinícius "Cabessa" Fernandes dos Santos Brazil
Timelimit: 1
In motorsports it is very common that the leader pilot in a race, at a certain moment, overtakes the last pilot. The leader, at this moment, is one lap ahead of the last pilot, who then becomes a straggler. In this task, given the time it takes for the fastest pilot, and for the slowest pilot, to complete one lap, you have to determine in which lap the slowest pilot will become a straggler. You should consider that, at the beginning, they are side by side at the start line of the circuit, both at the start of lap number 1 (the first lap of the race); and that a new lap always begins right after the leader crosses the start line.
Input
The input contains several test cases. Each test case consists of one line with two integers X and Y (1 ≤ X < Y ≤ 10000), the times, in seconds, that it takes for the fastest and the slowest pilot, respectively, to complete one lap.
Output
For each test case in the input program should output line, containing one integer: the lap in which the slowest pilot will become a straggler.
Sample Input | Sample Output |
5 7 |
4 |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
#include <math.h>
int main(void) {
double a, b;
scanf("%lf %lf", &a, &b);
printf("%d\n", (int)ceil(b / (b - a)));
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#2 Code Example with C++ Programming
Code -
C++ Programming
#include <iostream>
#include <cmath>
using namespace std;
int main(void) {
double a, b;
cin >> a >> b;
cout << ceil(b / (b - a)) << endl;
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#3 Code Example with Python Programming
Code -
Python Programming
from math import ceil
e = str(input()).split()
a = int(e[0])
b = int(e[1])
print(ceil(b / (b - a)))
Copy The Code &
Try With Live Editor
Input
Output