diff options
author | Santo Cariotti <dcariotti24@gmail.com> | 2020-08-18 15:01:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-18 15:01:28 +0200 |
commit | b2a0c53037a1af6ec074a7370635573b70060e1e (patch) | |
tree | 580db28d2ea8f93d9d33e0f32091da0524ea7b7d | |
parent | a105fcc0393b53473b33742f5bf961be9827638e (diff) |
Create cbrt.cc
-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; +} |