Prb de revizuit: -ksort
-
Verif cub si patrat perf
bool is_perfect_square(int n) {
if (n < 0)
return false;
int root(round(sqrt(n)));
return n == root * root;
}
bool is_perfect_cube(int n) {
int root(round(cbrt(n)));
return n == root * root * root;
}
prim eficient:
int prim(int n)
{
if(n 0 || n 1) return 0;
if(n 2) return 1;
if(n % 2 0) return 0;
for(int i = 3 ; i * i <= n ; i += 2) if(n % i == 0) return 0;
return 1;
}
/// scrierea unui nr binar -> punerea bitilor lui intr un vector
void bin(unsigned n,int &k)
{
/* step 1 */
if (n > 1)
bin(n / 2,k);
/* step 2 */
a[++k] = n % 2;
}
Ex:
17 -> 10001