C. C. Blog

Security Research, Algorithm and Data Structure

51Nod 1073 约瑟夫环

题意

编号1~N,每数K个出局,范围1e6

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<iostream>
#include<cstdio>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
ll n,k;
ll cur;
int main(){
cin>>n>>k;
cur=0;
for(int i=2;i<=n;i++){
cur=(cur+k)%i;
}
cur++;
cout<<cur<<endl;
return 0;
}
  • 本文作者: CCWUCMCTS
  • 本文链接: https://ccwucmcts.github.io/posts/60741/
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!