题目: https://atcoder.jp/contests/abc290/tasks/abc290_d

题解:

代码:
// Problem: D - Marking
// Contest: AtCoder - Toyota Programming Contest 2023 Spring Qual B(AtCoder Beginner Contest 290)
// URL: https://atcoder.jp/contests/abc290/tasks/abc290_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5+5;
int n,d,k;
int gcd(int x,int y){
	if(y==0) return x;
	return gcd(y,x%y);
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int T;
	cin>>T;
	while(T--){
		cin>>n>>d>>k;
		int g=gcd(n,d);
		//t为所在组编号
		int t=(k-1)/(n/g);
		cout<<((k-1)*d+t)%n<<"\n";
		
	}
	
	return 0;	
}
 
                


















