51nod1073 约瑟夫环

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_37275680/article/details/82630472

传送门:51nod1073 约瑟夫环

用数学方法解约瑟夫环 看了一下午,仍然没彻底看懂。

Input示例

3 2

Output示例

3
//数学方法解约瑟夫环,看了一下午,没看懂 
#include<iostream>
using namespace std;
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	int f=0;
	for(int i=2;i<=n;i++){
		f=(f+k)%i;
	}
	printf("%d\n",f+1);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_37275680/article/details/82630472