fork download
  1. template <typename T>
  2. T reduce2(T v) {
  3. T k = ((v * 410) >> 12) & 0x000F000F000F000Full;
  4. return (((v - k * 10) << 8) + k);
  5. }
  6.  
  7. template <typename T>
  8. T reduce4(T v) {
  9. T k = ((v * 10486) >> 20) & 0xFF000000FFull;
  10. return reduce2(((v - k * 100) << 16) + (k));
  11. }
  12.  
  13. typedef unsigned long long ull;
  14. inline ull reduce8(ull v) {
  15. ull k = ((v * 3518437209u) >> 45);
  16. return reduce4(((v - k * 10000) << 32) + (k));
  17. }
  18.  
  19. template <typename T>
  20. std::string itostr(T o) {
  21. union {
  22. char str[16];
  23. unsigned short u2[8];
  24. unsigned u4[4];
  25. unsigned long long u8[2];
  26. };
  27.  
  28. unsigned v = o < 0 ? ~o + 1 : o;
  29.  
  30. u8[0] = (ull(v) * 3518437209u) >> 45;
  31. u8[0] = (u8[0] * 28147497672ull);
  32. u8[1] = v - u2[3] * 100000000;
  33.  
  34. u8[1] = reduce8(u8[1]);
  35. char* f;
  36. if (u2[3]) {
  37. u2[3] = reduce2(u2[3]);
  38. f = str + 6;
  39. } else {
  40. unsigned short* k = u4[2] ? u2 + 4 : u2 + 6;
  41. f = *k ? (char*)k : (char*)(k + 1);
  42. }
  43. if (!*f) f++;
  44.  
  45. u4[1] |= 0x30303030;
  46. u4[2] |= 0x30303030;
  47. u4[3] |= 0x30303030;
  48. if (o < 0) *--f = '-';
  49. return std::string(f, (str + 16) - f);
  50. }
  51.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout

Standard output is empty