Advertisement
a53

PatratMagic4_Oficiala

a53
Sep 14th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int c;
  8. cin>>c;
  9. /// rezolvam ec. (n*n*n + n)/2 = c, folosind ec de gr 3 redusa
  10. /// cum avem 2 sol complexe, calculam doar cea reala
  11. double v1 = cbrt(c*1.0+sqrt(1.0/27.0+c*c*1.0));
  12. double v2 = cbrt(c*1.0-sqrt(1.0/27.0+c*c*1.0));
  13. double n = v1+v2;
  14. /// in mod mormal, avem n o valoare intreaga, dar datorita
  15. /// impreciziei tipului double/float, rotunjim si verificam
  16. int rez = 0;
  17. int eroare = 1;
  18. for(int i=n-eroare;i<=n+eroare;++i)
  19. if((i*i*i+i)/2 == c){
  20. rez = i;
  21. break;
  22. }
  23. cout<<rez;
  24. return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement