fork download
  1. #include <bits/stdc++.h>
  2. inline long long read()
  3. {
  4. long long sign = 1;
  5. long long x = 0;
  6. char ch;
  7. while (!isdigit(ch = getchar())) if (ch == '-') sign = -1;
  8. while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  9. return x * sign;
  10. }
  11. inline void wonl()
  12. {
  13. putchar('\n');
  14. }
  15. inline void ww(long long k)
  16. {
  17. if (k < 0) putchar('-'), k *= -1;
  18. char ch[20];
  19. int num = 0;
  20. while (k)ch[++num] = k % 10, k /= 10;
  21. if (num == 0) ch[++num] = 0;
  22. while (num)putchar(ch[num--] + '0');
  23. }
  24. using namespace std;
  25. const long long N = 1e17 + 4;
  26. const long long N1 = 1e12 + 4;
  27. template <typename T, typename... V>
  28. inline void wonl(T t, V... v)
  29. {
  30. ww(t);
  31. if (sizeof...(v))putchar(' ');
  32. wonl(v...);
  33. }
  34.  
  35.  
  36. int main()
  37. {
  38. int n = read(), ar[n];
  39. for (int ele = 0; ele < n; ele++)ar[ele] = read();
  40. sort(ar, ar + n);
  41. if (n > 65)
  42. {
  43. long long ans = 0;
  44. for (int i = 0; i < n; i++)
  45. {
  46. ans += ar[i] - 1;
  47. }
  48. wonl(ans);
  49. }
  50. else
  51. {
  52. long long fans = N;
  53. for (int c = 1; ; c++)
  54. {
  55. if (pow(c, n - 1) > N1)break;
  56. long long ter = 1, ans = 0;
  57. for (int i = 0; i < n; i++)
  58. {
  59. ans += abs(ar[i] - ter), ter = ter * c;
  60. }
  61. fans = min(fans, ans);
  62. }
  63. wonl(fans);
  64. }
  65. return 0;
  66. }
  67.  
  68.  
Time limit exceeded #stdin #stdout 5s 4392KB
stdin
Standard input is empty
stdout
Standard output is empty