-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathu.c
42 lines (42 loc) · 739 Bytes
/
u.c
1
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
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <math.h>
void desloveby2(int n);
int main(){
int n;
scanf("%d", &n);
desloveby2(n);
}
void desloveby2(int n){
if(n==1){
printf("2(0)");
}
else if(n==2){
printf("2");
}
else if(n==3){
printf("2+2(0)");
}
else if(n==4){
printf("2(2)");
}
else if (n==5){
printf("2(2)+2(0)");
}
else{
int i=0;
while(n>pow(2,i)){
i++;
}
if(n==pow(2,i)){
printf("2(");
desloveby2(i);
printf(")");
}
else{
printf("2(");
desloveby2(i-1);
printf(")+");
desloveby2(n-pow(2,i-1));
}
}
}