Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- long long k, d, t, m, c, sol;
- cin >> k >> d >> t;
- long long nr = k / d;
- if(nr * d < k)
- m = (nr + 1) * d;
- else
- m = nr * d;
- c = (2LL * t) / (m + k);
- sol = c * m;
- t -= c * ((m + k) / 2);
- bool r = false;
- if((m + k) % 2 == 1) {
- t -= c / 2;
- if(c % 2 == 1) {
- t -= 1;
- r = true;
- }
- }
- if(t < k) {
- sol += t;
- cout << sol;
- if(r)
- cout << ".5";
- }
- else if(t == k) {
- sol += t;
- if(r)
- sol += 1;
- cout << sol << ".0";
- }
- else {
- sol += k;
- t -= k;
- sol += 2 * t;
- if(r)
- sol += 1;
- cout << sol << ".0";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement