fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int fun(int mid,int m){
  4. int ans=1;
  5. for(int i=1;i<=m;i++){
  6. ans=ans*mid;
  7. }
  8. return ans;
  9. }
  10. int main()
  11. {
  12. int n,m;
  13. cin>>n>>m;
  14.  
  15. int l=0,r=n;
  16. while(l<=r){
  17. int mid=l+(r-l)/2;
  18. if(fun(mid,m)>n){
  19. r=mid-1;
  20. }
  21. else if(fun(mid,m)<n){
  22. l=mid+1;
  23. }
  24. else{
  25. cout<<mid<<endl;
  26. return 0;
  27. }
  28. }
  29. cout<<m<<"th root of "<<n<<" is not possible( in integer)"<<endl;
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5308KB
stdin
Standard input is empty
stdout
32765th root of 198165936 is not possible( in integer)