soj 3915 sretan

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 去掉就可以了…代码很好写了……

代码如下:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值