标签:using namespace cin efi main algo r++ 题意 51nod
约瑟夫环,N-1e18,K-1000
由于K远小于N,后面i大了之后某些时候不用取模,可以加速。
#include<iostream>
#include<cstdio>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
ll n,k;
ll cur,t;
int main(){
cin>>n>>k;
cur=0;
for(ll i=2;i<=n;i+=t+1){
t=(i-cur)/k-1;
if(t<0) t=0;
if(i+t+1>n) t=n-i;
cur=(cur+(t+1)*k)%(i+t);
}
cur++;
cout<<cur<<endl;
return 0;
}
标签:using namespace cin efi main algo r++ 题意 51nod
原文地址:https://www.cnblogs.com/sz-wcc/p/11231635.html