diff options
Diffstat (limited to 'I_anno')
-rw-r--r-- | I_anno/Programmazione_2/algorithms/cbrt.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/I_anno/Programmazione_2/algorithms/cbrt.cc b/I_anno/Programmazione_2/algorithms/cbrt.cc new file mode 100644 index 0000000..bbd1ee1 --- /dev/null +++ b/I_anno/Programmazione_2/algorithms/cbrt.cc @@ -0,0 +1,24 @@ +#include<iostream> + +using namespace std; + +int cbrt(int n) { + int i = 0; + int j = n; + int q = (i+j)/2; + while(q*q*q != n) { + q = (i+j)/2; + if(q*q*q < n) + i=q; + else + j=q; + } + return q; +} + +int main() { + int i; + cin >> i; + cout << i << ' ' << cbrt(i) << endl; + return 0; +} |