Strange Table CodeForces
import java.util.Scanner;
class CodeForces7{
public static void main(String arg[]){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t -->0){
long n=sc.nextLong();
long m=sc.nextLong();
long x=sc.nextLong();
//long arr[][]=new long[n][m];
//By rows
/*
for(int i=1;i<n*m+1;i++){
if(i%m==0){
System.out.print(i);
System.out.println();
}
else
System.out.print(i+" ");
}*//*
int count=0;
for(int i=1;i<n+1;i++){
for(int j=i;j<=(m*n);j+=n){
count++;
if(count%m==0){
System.out.println();
}
else
System.out.print(j+" ");
}
}
for(int i=1;i<2;i++){
System.out.print(i+" ");
for(int j=i+1;j<=(m*n);j++){
//count++;
if(j%m==0){
System.out.print(j);
System.out.println();
}
else
System.out.print(j+" ");
}
}
/*
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
long arr2[][]=new long[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
arr2[i][j]=sc.nextLong();
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
System.out.print(arr2[i][j]+" ");
}
System.out.println();
}
*//*
for(int i=1;i<m*n+1;i+=n)
{
for(int j=i;j<n+i;j++){
if(j%n==0){
System.out.println(j+" ");
break;
}
else{
System.out.print(j+" ");
}
}
}
}
*/
long a=0;
long b=0;
long c=0;
if(x%n==0){
b=x/n;
a=n;
}
else
{
a=x%n;
b=x/n+1;
}
c=m*(a-1)+b;
System.out.println(c);
}
}
}
Comments
Post a Comment