This is a problem of case study and math. Create a program that simulates the process and find the pattern.
Inputs
Once you find the pattern its straightforward.
1. Find the nearest 2^X such that 2^X <= N
2. If 2^X == N, output N
Else output (N-2^X)*2
Inputs
1Outputs:
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
1
2
2
4
2
4
6
8
2
4
6
8
10
12
14
16
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
Once you find the pattern its straightforward.
1. Find the nearest 2^X such that 2^X <= N
2. If 2^X == N, output N
Else output (N-2^X)*2
No comments:
Post a Comment
Post your comment here. If you want to say something about programming problems, scripts, software etc, please try to be as descriptive as possible.