ABC 290 D - Marking (數學)
阿新 • 來源:網路 • 發佈:2023-02-22
https://atcoder.jp/contests/abc290/tasks/abc290_d
題目大意:
一開始總共有N個方塊,下標為0,1,2,3,4...n-1,一開始都沒有標記。
給定整數D和K,執行K次操作,問第K次標記的方塊是第幾個?
具體規則:
第一次操作:給0標記
然後:給(lastidx+D)%N標記 ;如果這個位置已經被標記過,進行(lastidx+1)%N運算找到未被標記過的地方並且標記。
Sample Input 1
9
4 2 1
4 2 2
4 2 3
4 2 4
5 8 1
5 8 2
5 8 3
5 8 4
5 8 5
Sample Output 1
0
2
1
3
0
3
1
4
2
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=31;
const LL N=1e6+10,M=4010;
const double PI=3.1415926535;
#define endl '\n'
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
int T=1;
//cin>>T;
while(T--)
{
LL t;
cin>>t;
for(int i=1;i<=t;i++)
{
LL n,d,k;
cin>>n>>d>>k;
k--;
LL flag=n/__gcd(n,d);
cout<<(LL)d*k%n+k/flag<<endl;
}
}
return 0;
}
