CF2260B.Monocarp and Projects

入门

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Monocarp runs a company. Consider the work of his company over the next kk months. In the first month, the company has xx employees, not counting Monocarp himself, and yy projects need to be completed. In each next month, both the number of employees and the number of projects increase by 11.

In other words, in month ii (0≤i<k0 \le i \lt k), the company has x+ix+i employees and needs to complete y+iy+i projects.

In each month, Monocarp distributes the projects among the employees. Each employee must receive the same number of projects, and each project can be assigned to at most one employee. Monocarp completes all unassigned projects himself. He always chooses a distribution that makes him complete as few projects as possible.

In particular, if in some month there are aa employees and bb projects, then Monocarp assigns exactly ⌊ba⌋\left\lfloor \frac{b}{a} \right\rfloor projects to each employee, and he completes b mod ab \bmod a projects himself.

Find the total number of projects that Monocarp will complete himself over the next kk months.

Monocarp 经营着一家公司。考虑该公司在未来 kk 个月内的情况。在第一个月,公司有 xx 名员工(不包括 Monocarp 本人),且需要完成 yy 个项目。在接下来的每个月中,员工人数和项目数量均增加 11。

换句话说,在第 ii 个月(0≤i<k0 \le i < k),公司有 x+ix+i 名员工,且需要完成 y+iy+i 个项目。

在每个月中,Monocarp 将项目分配给员工。每名员工必须分配到相同数量的项目,且每个项目最多只能分配给一名员工。所有未被分配的项目均由 Monocarp 自己完成。他总是选择一种分配方式,使得自己完成的项目数尽可能少。

特别地,若某个月有 aa 名员工和 bb 个项目,则 Monocarp 恰好为每名员工分配 ⌊ba⌋\left\lfloor \frac{b}{a} \right\rfloor 个项目,而他自己完成 b mod ab \bmod a 个项目。

求 Monocarp 在未来 kk 个月内总共需要自己完成的项目数。

输入格式

The first line contains an integer tt — the number of test cases (1≤t≤1041 \le t \le 10^4).

Each test case consists of one line containing three integers xx, yy, and kk (1≤x≤y≤1061 \le x \le y \le 10^6; 1≤k≤10121 \le k \le 10^{12}).

Additional constraint on the input:

  • the sum of yy over all test cases does not exceed 10610^6.

第一行包含一个整数 tt —— 测试用例的数量(1≤t≤1041 \le t \le 10^4)。

每个测试用例由一行组成,包含三个整数 xx、yy 和 kk(1≤x≤y≤1061 \le x \le y \le 10^6;1≤k≤10121 \le k \le 10^{12})。

输入的额外约束条件:

  • 所有测试用例的 yy 值之和不超过 10610^6。

输出格式

For each test case, output one integer — the total number of projects that Monocarp will complete himself over kk months.

对于每个测试用例,输出一个整数——Monocarp 在 kk 个月内将亲自完成的项目总数。

输入输出样例

  • 输入#1

    7
    1 1 1
    3 10 2
    3 8 6
    7 20 1
    10 25 100
    8 36 17
    1 999900 1000000000000

    输出#1

    0
    4
    18
    6
    1425
    110
    999898177699820694

说明/提示

In the first test case, the only employee completes the only project, so Monocarp is left with no projects.

In the second test case, in the first month, 1010 projects are distributed among 33 employees: each gets 33 projects, and Monocarp completes 11 project. In the second month, 1111 projects are distributed among 44 employees: each gets 22 projects, and Monocarp completes 33 projects. The answer is 1+3=41 + 3 = 4.

In the third test case, the number of projects completed by Monocarp in the six months is 22, 11, 00, 55, 55, and 55, respectively. Their sum is 2+1+0+5+5+5=182 + 1 + 0 + 5 + 5 + 5 = 18.

在第一个测试用例中,唯一的一名员工完成了唯一的项目,因此 Monocarp 没有剩余项目。

在第二个测试用例中,第一个月将 1010 个项目分配给 33 名员工:每人分得 33 个项目,Monocarp 完成 11 个项目;第二个月将 1111 个项目分配给 44 名员工:每人分得 22 个项目,Monocarp 完成 33 个项目。答案为 1+3=41 + 3 = 4。

在第三个测试用例中,Monocarp 在六个月中完成的项目数分别为 22、11、00、55、55 和 55。它们的总和为 2+1+0+5+5+5=182 + 1 + 0 + 5 + 5 + 5 = 18。

输入解题思路,AI测评打分。不知道怎么写?

首页