CF1506A.Strange Table

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Polycarp found a rectangular table consisting of nn rows and mm columns. He noticed that each cell of the table has its number, obtained by the following algorithm "by columns":

  • cells are numbered starting from one;
  • cells are numbered from left to right by columns, and inside each column from top to bottom;
  • number of each cell is an integer one greater than in the previous cell.

For example, if n=3n = 3 and m=5m = 5, the table will be numbered as follows:

\\begin{matrix} 1 & 4 & 7 & 10 & 13 \\\\ 2 & 5 & 8 & 11 & 14 \\\\ 3 & 6 & 9 & 12 & 15 \\\\ \\end{matrix}

However, Polycarp considers such numbering inconvenient. He likes the numbering "by rows":

  • cells are numbered starting from one;
  • cells are numbered from top to bottom by rows, and inside each row from left to right;
  • number of each cell is an integer one greater than the number of the previous cell.

For example, if n=3n = 3 and m=5m = 5, then Polycarp likes the following table numbering: $$ \begin{matrix} 1 & 2 & 3 & 4 & 5 \\ 6 & 7 & 8 & 9 & 10 \\ 11 & 12 & 13 & 14 & 15 \\ \end{matrix} $$

Polycarp doesn't have much time, so he asks you to find out what would be the cell number in the numbering "by rows", if in the numbering "by columns" the cell has the number xx?

Polycarp 发现了一个由 nn 行和 mm 列组成的矩形表格。他注意到表格中的每个单元格都有一个编号,该编号是按如下“按列编号”算法得到的:

  • 单元格编号从 1 开始;
  • 单元格按列从左到右编号,且在每一列内从上到下编号;
  • 每个单元格的编号比前一个单元格的编号大 1。

例如,若 n=3n = 3 且 m=5m = 5,则表格将按如下方式编号:

147101325811143691215\begin{matrix} 1 & 4 & 7 & 10 & 13 \\ 2 & 5 & 8 & 11 & 14 \\ 3 & 6 & 9 & 12 & 15 \\ \end{matrix}

然而,Polycarp 认为这种编号方式不够方便。他更喜欢“按行编号”方式:

  • 单元格编号从 1 开始;
  • 单元格按行从上到下编号,且在每一行内从左到右编号;
  • 每个单元格的编号比前一个单元格的编号大 1。

例如,若 n=3n = 3 且 m=5m = 5,则 Polycarp 更喜欢如下表格编号方式:

123456789101112131415\begin{matrix} 1 & 2 & 3 & 4 & 5 \\ 6 & 7 & 8 & 9 & 10 \\ 11 & 12 & 13 & 14 & 15 \\ \end{matrix}

Polycarp 时间不多,因此请你帮忙找出:若某个单元格在“按列编号”方式下的编号为 xx,那么它在“按行编号”方式下的编号是多少?

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4). Then tt test cases follow.

Each test case consists of a single line containing three integers nn, mm, xx (1≤n,m≤1061 \le n, m \le 10^6, 1≤x≤n⋅m1 \le x \le n \cdot m), where nn and mm are the number of rows and columns in the table, and xx is the cell number.

Note that the numbers in some test cases do not fit into the 3232-bit integer type, so you must use at least the 6464-bit integer type of your programming language.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)。随后是 tt 组测试数据。

每组测试数据由一行组成,包含三个整数 nn、mm、xx(1≤n,m≤1061 \le n, m \le 10^6,1≤x≤n⋅m1 \le x \le n \cdot m),其中 nn 和 mm 分别表示表格的行数和列数,xx 表示单元格编号。

注意:某些测试用例中的数值无法放入 3232 位整数类型中,因此你必须至少使用编程语言中的 6464 位整数类型。

输出格式

For each test case, output the cell number in the numbering "by rows".

对于每个测试用例,输出该单元格在“按行编号”方式下的编号。

输入输出样例

  • 输入#1

    5
    1 1 1
    2 2 3
    3 5 11
    100 100 7312
    1000000 1000000 1000000000000

    输出#1

    1
    2
    9
    1174
    1000000000000

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

首页