3915: sretan
Digits 4 and 7 are lucky, while all others are unlucky. An integer is lucky if it contains only lucky digits
in decimal notation. We would like to know the K-th lucky positive integer.
Input
The first and only line of input contains a positive integer K (1 ≤ K ≤ 10 9 ).
Output
The first and only line of output must contain the K-th lucky positive integer.
Sample Input
1
2
3
Sample Output
4
7
44
Source
coci 2010/2011 contest 1
题意很简单,问只含有数字4 和 7 的第 k 大数字……
这题反应了好久……估计老了……orz
是这样的
1 4
2 7
3 44
4 47
5 74
6 77
不列了,发现只有两个数字,完全可以用0 和 1 来表示,这样就有,如果用 0 表示 4,1 表示 7 ,则有:
1 0
2 1
3 00
4 01
5 10
6 11
发现了个问题没……如果在前面都加个1 ,那么会得到下列数列
1 10
2 11
3 100
4 101
5 110
6 111
一眼看出是n+1 的二进制…所以求出 n+1 的二进制后只要把前面的 0 去掉就可以了…代码很好写了……
代码如下: