fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using ll = long long;
  4. const int MX = 1e9;
  5.  
  6. int32_t main() {
  7. std::ios::sync_with_stdio(false);
  8. std::cin.tie(nullptr), std::cout.tie(nullptr);
  9.  
  10. std::vector<ll> sizes = {0};
  11. for (int i = 1; ; i++) {
  12. ll cand = 1ll * i * (i - 1) / 2;
  13. if (cand > MX) break;
  14. sizes.push_back(cand);
  15. }
  16.  
  17. int tests;
  18. std::cin >> tests;
  19.  
  20. for (int _ = 1; _ <= tests; _++) {
  21. int n;
  22. std::cin >> n;
  23.  
  24. std::vector<int> index;
  25.  
  26. while (n) {
  27. auto it = std::upper_bound(sizes.begin(), sizes.end(), n);
  28. --it;
  29. n -= static_cast<int>(*it);
  30. index.push_back(static_cast<int>(it - sizes.begin()));
  31. }
  32. std::sort(index.begin(), index.end());
  33.  
  34. std::string ans = "1";
  35. int j = 0, cur = 0;
  36. while (j < index.size()) {
  37. cur++;
  38. ans += '3';
  39. while (j < index.size() && index[j] == cur) {
  40. ans += '7';
  41. j++;
  42. }
  43. }
  44.  
  45. std::cout << ans.size() << std::endl;
  46. }
  47.  
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0.01s 5288KB
stdin
10
1000000000
999999937
536870912
387420489
996919243
999634589
223092870
999999986
999999939
999999955
stdout
44727
44726
32773
27841
44658
44719
21129
44726
44725
44727