bhupixb

nTh root of a number

Jan 21st, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. // I can't tell you what it really is,
  2. // I can only tell you what it feels like.
  3. #include "bits/stdc++.h"
  4. using namespace std;
  5. #define int long long
  6. #define ld long double
  7.  
  8. signed main() {
  9. ios::sync_with_stdio(false);
  10. cin.tie(0);
  11. int A, N;
  12. cin >> A >> N;
  13. ld ans = -1, lo = 1, hi = 20;
  14. const ld inf = 1e-14;
  15. const ld preLog = log(A);
  16. // cout << preLog << '\n';
  17. while (!(hi-lo<=inf)) {
  18. ld mid = (lo+hi)/2.0;
  19. // cout << N*log(mid) << ' ' << preLog << '\n';
  20. if (preLog-N*log(mid) >= inf) {
  21. lo = mid + inf;
  22. ans = mid;
  23. }
  24. else hi = mid - inf;
  25. }
  26. cout << fixed << setprecision(10) << ans;
  27. return 0;
  28. }
  29. // 1). Try forming/rearranging the equations if any
  30. // 2). If problem asks to count, try counting in reverse(it can be easier sometimes)
Add Comment
Please, Sign In to add comment