Comet Sister recently built a train and named it the "Comet Train." The most notable feature of this Comet Train is that it continuously accelerates at a fixed rate per second.
For example, if the Comet Train wants to accelerate from rest to 100 km/s with an acceleration of 25 km/s, it will take 4 seconds to reach its goal.
Given the Comet Train's acceleration per second and the desired speed the train is expected to reach, please write a program to calculate how many seconds it will take for the train to reach the specified speed.
Sample Inputs/Outputs
Sample Input(s) | Sample Output(s) |
---|---|
The input consists of two integers, A (where 1 ≤ A ≤ 10^8) and S (where 1 ≤ S ≤ 10^9). Here, A represents the acceleration per second of the train, and S represents the desired speed of the train. The two numbers are separated by a single space. | Output an integer representing the minimum number of seconds it takes to reach the desired target speed. |
25 100 | 4 |
3 200 | 67 |
Thought Process
The answer is S/A. You can take the integer inputs and perform integer division, which automatically rounds down.
If S%A is not equal to 0, you need to add 1 to the answer because it should be rounded up.
Sample Code-ZeroJudge G496: Comet Train
#include <iostream>
using namespace std;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int a, b;
cin >> a >> b;
int ans = b/a;
if (b % a != 0) ans++;
cout << ans << "\n";
}
//Z.O.J. G496
//Dr. SeanXD