隐藏
「十连赛NOIPday5」约瑟夫游戏 - 数学 | Bill Yang's Blog

路终会有尽头,但视野总能看到更远的地方。

0%

「十连赛NOIPday5」约瑟夫游戏 - 数学

题目大意

$YJC$很喜欢玩游戏,今天他决定和朋友们玩约瑟夫游戏。
约瑟夫游戏的规则是这样的:$n$个人围成一圈,从$1$号开始依次报数,当报到$m$时,报$1,2,\ldots,m-1$的人出局,下一个人接着从$1$开始报,保证$(n-1)$是$(m-1)$的倍数。最后剩的一个人获胜。
$YJC$很想赢得游戏,但他太笨了,他想让你帮他算出自己应该站在哪个位置上。


题目分析

四校联考的第一题一模一样。


代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
typedef long long LL;
inline const LL Get_Int() {
LL num=0,bj=1;
char x=getchar();
while(x<'0'||x>'9') {
if(x=='-')bj=-1;
x=getchar();
}
while(x>='0'&&x<='9') {
num=num*10+x-'0';
x=getchar();
}
return num*bj;
}
LL n,m;
LL Solve(LL x) {
if(x==1)return 1;
return m*(Solve(x/m+x%m)-x%m);
}
int main() {
n=Get_Int();
m=Get_Int();
printf("%lld\n",Solve(n));
return 0;
}
姥爷们赏瓶冰阔落吧~