- 李红强 的博客
Day 14
- @ 2025-7-29 10:14:03
T4
有N个方块排成一列,编号从0--(n-1),有以下步骤标记方块
- 令% A为上次标记的地方
- 若x已经被标记,替换%
- 标记x
题目要求:输出第次标记的方块的编号
#include<bits/stdc++.h>
using namespace std;
long long t,k,n,d;
long long gcd(long long a,long long b){
if(b==0) return a;
return gcd(b,a%b);
}
int main(){
freopen("D.in","r",stdin);
freopen("D.out","w",stdout);
cin>>t;
while(t--){
cin>>n>>d>>k;
if(k==1){
cout<<0<<endl;
continue;
}
k--;
cout<<(k*d+k/(n/gcd(n,d)))%n<<endl;
}
return 0;
}