#include #include #include typedef unsigned long long u64; u64 div64_u64_rem(u64 a, u64 b, u64 *rem) { u64 res = a / b; *rem = a % b; return res; } u64 div64_u64(u64 a, u64 b) { return a / b; } u64 scale_stime(u64 stime, u64 rtime, u64 total) { u64 rem, res, scaled; if (rtime >= total) { res = div64_u64_rem(rtime, total, &rem); scaled = stime * res; scaled += div64_u64(stime * rem, total); } else { res = div64_u64_rem(total, rtime, &rem); scaled = div64_u64(stime, res); scaled -= div64_u64(scaled * rem, total); } return scaled; } int main(int argc, char *argv[]) { u64 rtime, total, stime, scaled; if (argc != 4) return -1; rtime = strtoll(argv[1], NULL, 10); total = strtoll(argv[2], NULL, 10); stime = strtoll(argv[3], NULL, 10); assert (total >= stime); scaled = scale_stime(stime, rtime, total); printf("%llu\n", scaled); return 0; }