fork download
  1. #include<bits/stdc++.h>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. #define MOD 1000000007
  6. #define MAX 2010
  7. #define ll long long
  8. #define slld(t) scanf("%lld",&t)
  9. #define sd(t) scanf("%d",&t)
  10. #define sld(t) scanf("%ld",&t)
  11. #define pd(t) printf("%d\n",t)
  12. #define plld(t) printf("%lld\n",t)
  13. #define pcc pair<char,char>
  14. #define pp pair<int,int>
  15. #define pll pair<ll,ll>
  16. #define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
  17. #define mp(a,b) make_pair(a,b)
  18. #define F first
  19. #define S second
  20. #define pb(x) push_back(x)
  21.  
  22. vector <ll> ans;
  23. int main()
  24. {
  25. ll n,k;
  26. slld(n); slld(k);
  27. if(k>n/2)
  28. {
  29. k = n-k;
  30. }
  31. ll cur = 1+k;
  32. ll an = 2; ll p = 1;
  33. ans.pb(2LL);
  34. for( int i=2; i<=n; i++)
  35. {
  36. cur += k;
  37. if(cur>n)
  38. {
  39. cur %= n;
  40. p++;
  41. an+=p;
  42. p++;
  43. ans.pb(an);
  44. }
  45. else
  46. {
  47. an += p;
  48. ans.pb(an);
  49. }
  50. }
  51. for( int i=0; i<ans.size(); i++)
  52. {
  53. if(i==ans.size()-1)
  54. {
  55. ans[i] -= 1;
  56. }
  57. cout<<ans[i]<<" ";
  58. }
  59. }
Runtime error #stdin #stdout #stderr 0.51s 528896KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc