fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. ios_base::sync_with_stdio(0);
  7. long long a;
  8. cin >> a;
  9. if(a == 1)
  10. {
  11. cout << "LGPD";
  12. return 0;
  13. }
  14. long long l = 1,p= 1000000,mid;
  15. while(l < p)
  16. {
  17. mid = (l+p+1)/2;
  18. if(mid*mid == a)
  19. {
  20. for(int i = 0;i < mid;++i) cout << 'L';
  21. for(int i = 0;i < mid;++i) cout << 'G';
  22. for(int i = 0;i < mid;++i) cout << 'P';
  23. for(int i = 0;i < mid;++i) cout << 'D';
  24. return 0;
  25. }
  26. if(mid*mid > a)
  27. {
  28. p = mid-1;
  29. }
  30. if(mid*mid < a)
  31. {
  32. l = mid;
  33. }
  34.  
  35. }
  36. long long wyn = l*l;
  37. if((a-wyn) <= l)
  38. {
  39. for(int i = 0;i < l+1;++i) cout << 'L';
  40. for(int i = 0;i < (a-wyn);++i) cout << 'G';
  41. cout << 'P';
  42. for(int i = 0;i < l-(a-wyn);++i) cout << 'G';
  43. for(int i = 0;i < l;++i) cout << 'P';
  44. for(int i = 0;i < l;++i) cout << 'D';
  45. return 0;
  46. }
  47. else
  48. {
  49. for(int i = 0;i < l+1;++i) cout << 'L';
  50. for(int i = 0;i < l;++i) cout << 'G';
  51. cout << 'P';
  52. cout << 'G';
  53. for(int i = 0;i < (a-wyn-l);++i) cout << 'P';
  54. cout << "D";
  55. for(int i = 0;i < l-(a-wyn-l);++i) cout << 'P';
  56. for(int i = 0;i < l;++i) cout << 'D';
  57. }
  58. }
  59.  
Success #stdin #stdout 0s 5284KB
stdin
2137
stdout
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLGGGGGGGGGGGGGGGGGGGGGPGGGGGGGGGGGGGGGGGGGGGGGGGPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD