Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int c;
- cin>>c;
- /// rezolvam ec. (n*n*n + n)/2 = c, folosind ec de gr 3 redusa
- /// cum avem 2 sol complexe, calculam doar cea reala
- double v1 = cbrt(c*1.0+sqrt(1.0/27.0+c*c*1.0));
- double v2 = cbrt(c*1.0-sqrt(1.0/27.0+c*c*1.0));
- double n = v1+v2;
- /// in mod mormal, avem n o valoare intreaga, dar datorita
- /// impreciziei tipului double/float, rotunjim si verificam
- int rez = 0;
- int eroare = 1;
- for(int i=n-eroare;i<=n+eroare;++i)
- if((i*i*i+i)/2 == c){
- rez = i;
- break;
- }
- cout<<rez;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement