ABC 290 D - Marking (数学)

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;
}
posted @ 2023-02-22 21:24  高尔赛凡尔娟  阅读(56)  评论(0编辑  收藏  举报