Advertisement
newb_ie

with_bs

Sep 4th, 2021
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main () {
  5. ios::sync_with_stdio(false);
  6. cin.tie(nullptr);
  7. cout.tie(nullptr);
  8. vector<long long> a;
  9. for (long long i = 1; i <= 10000; ++i) {
  10. long long p = pow(i,3);
  11. a.push_back(p);
  12. }
  13. int T;
  14. cin >> T;
  15. for (int test_case = 1; test_case <= T; ++test_case) {
  16. long long n;
  17. cin >> n;
  18. bool f = false;
  19. for (int i = 0; i < 10000; ++i) {
  20. long long x = a[i];
  21. long long y = n - x;
  22. int l = 0,r = 10000 - 1;
  23. //binary_search(a.begin(),a.end(),x); => true,false
  24. //~ if (binary_search(a.begin(),a.end(),y)) {
  25. //~ f = true;
  26. //~ break;
  27. //~ }
  28. while (l <= r) {
  29. int m = (l + r) / 2;
  30. if (a[m] == y) {
  31. f = true;
  32. break;
  33. } else if (a[m] > y) r = m - 1;
  34. else l = m + 1;
  35. }
  36. }
  37. if (f) {
  38. cout << "YES\n";
  39. } else {
  40. cout << "NO\n";
  41. }
  42. }
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement