summaryrefslogtreecommitdiff
path: root/I_anno/Programmazione_2/algorithms/cbrt.cc
blob: bbd1ee146054a6d96805414abbd0957ad58b3cd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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;
}