Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #pragma comment(linker,"/STACK:64000000")
  2.  
  3. #include <iostream>
  4. #include <fstream>
  5. #include <vector>
  6. #include <string>
  7.  
  8. using namespace std;
  9.  
  10. int answ[300001];
  11. int pirs[120];
  12.  
  13. void init_pirs()
  14. {
  15.     int cur = 3;
  16.     pirs[0] = 1;
  17.  
  18.     for (int i = 1; i < 120; ++i) {
  19.         pirs[i] = pirs[i - 1] + cur;
  20.         cur += i + 2;
  21.     }
  22. }
  23.  
  24. void init_ans()
  25. {
  26.     init_pirs();
  27.     answ[0] = 0;
  28.  
  29.     for (int i = 1; i < 300001; ++i) {
  30.         int icur = 0;
  31.         while ((pirs[icur] <= i) && (icur < 120))
  32.             answ[i] = min(answ[i], 1 + pirs[icur]),
  33.             icur++;
  34.     }
  35. }
  36.  
  37. int main() {
  38.     init_ans();
  39.  
  40.     int t;
  41.     cin >> t;
  42.     for (int i = 0; i < t; ++i) {
  43.         int a;
  44.         cin >> a;
  45.         cout << answ[a] << endl;
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement