Guest User

Untitled

a guest
Jan 15th, 2017
287
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n, k;
  5. long long v, d;
  6.  
  7. int main(){
  8. ios_base::sync_with_stdio(false);
  9.  
  10. cin >> n >> k;
  11.  
  12. k = min(k, n - k);
  13.  
  14. p = 1;
  15. for(int i = 0; i < n; i++){
  16. if(v + k > n){
  17. d += 2;
  18. p += d;
  19. v = (v + k) % n;
  20. }else{
  21. p += d + 1;
  22. v += k;
  23. }
  24.  
  25. cout << p << ' ';
  26. }
  27.  
  28. return 0;
  29. }
RAW Paste Data