Skip to content

Instantly share code, notes, and snippets.

@lukasa1993
Created May 1, 2012 11:46
Show Gist options
  • Save lukasa1993/2567537 to your computer and use it in GitHub Desktop.
Save lukasa1993/2567537 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
using namespace std;
int customeAdd(int i,int N,int K)
{
if(i + K > N) {
return (i + K) - N;
}
return i + K;
}
int main()
{
int N = 0,K = 0,counter = 0,prevCounter = 0,tmpCount = 0;
cin>>N>>K;
vector<bool> numbers(N + 1,true);
counter = K;
for(int i = 0; i < N; i++) {
cout<<counter<<" ";
numbers[counter] = false;
for(int j = customeAdd(counter,N,1); ; j = customeAdd(j,N,1)) {
tmpCount++;
counter = customeAdd(counter,N,1);
if(numbers[j]) {
tmpCount = 0;
prevCounter++;
if(prevCounter == K) {
prevCounter = 0;
break;
}
}
if(tmpCount >N) {
break;
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment