My code:
Code: Select all
#include <stdio.h>
#include <math.h>
long long potenciasDois[50];
void CalculaPotencias() {
long long i;
long long x;
x = 1;
potenciasDois[0] = 0;
for (i=1; i < 40; i++) {
potenciasDois[i] = x;
x = x*2;
}
return ;
}
int PotenciaVef(long long numero) {
int i;
i = 0;
while (potenciasDois[i] < numero) {
i++;
}
if (potenciasDois[i] == numero) {
return i;
}
return 0;
}
int main (void) {
long long numero;
long long n;
CalculaPotencias();
while (scanf("%lld", &numero) != EOF) {
n = numero - 1 + floor(log2(numero));
if (numero % 2 == 0) {
if (PotenciaVef(numero)) {
n--;
}
}
printf("%lld\n", n);
}
return 0;
}
Code: Select all
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
7427466391
17179869184
512
1024
2048
4096
4097
Code: Select all
1
3
4
6
7
8
9
11
12
13
14
15
16
17
18
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
7427466422
17179869216
519
1032
2057
4106
4108