Advertisement
Galebickosikasa

Untitled

Apr 23rd, 2021
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. task 5
  2.  
  3. int kek (int n) {
  4. vector <int> a;
  5. while (n) {
  6. a.pb (n % 3);
  7. n /= 3;
  8. }
  9. reverse (all (a));
  10. int last = a.back ();
  11. fr (k, 3) {
  12. vector <int> cnt (3);
  13. for (auto& x: a) ++cnt[x];
  14. int f = 0;
  15. fr (i, 3) {
  16. fr (j, 3) {
  17. if (i == j) continue;
  18. f |= cnt[i] == cnt[j];
  19. }
  20. }
  21. if (f) a.pb (last);
  22. else {
  23. int mn = inf;
  24. for (auto& x: cnt) chkmin (mn, x);
  25. fr (i, 3) {
  26. if (cnt[i] == mn) a.pb (i);
  27. }
  28. }
  29. }
  30. reverse (all (a));
  31. int ans = 0;
  32. int p = 1;
  33. fr (i, sz (a)) {
  34. ans += a[i] * p;
  35. p *= 3;
  36. }
  37. return ans;
  38. }
  39.  
  40. signed main () {
  41. ios_base::sync_with_stdio (false);
  42. cin.tie (nullptr);
  43. fl (i, 71, 10000) {
  44. int x = kek (i);
  45. if (x % 2 == 0 && x % 6) {
  46. dbg (i);
  47. break;
  48. }
  49. }
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement