编程介的小学生 2017-09-09 03:01 采纳率: 20.5%
浏览 799
已采纳

Friend Number

Friend numbers are those who are composed of the same digits, for example 3123 and 11233233 are friend numbers, but 1233432 and 123331 are not friend numbers because in the second number the 4 is missing.

Your task is this: given an integer closed range [A, B], an integer number N and an integer K, you must find the Kth friend number of N in that range.

Input

Input will consist of several test cases each of them in a separate line. For each test case you will receive four (with no leading zeroes) integers A, B , N and K ( 0 < A<= B < 10^100 , 0 <= N <= 10^100 , 0 < K <= 10^17).

Output

For each test case you must print a line containing a number representing the Kth friend number in the given range, or "-1" if it is not possible to obtain the Kth friend number.

Sample Input

1 191010100333 1003 20000
1 200 1 3
1 200 1 4
1 200 211 1
1 200 211 2
1 200 211 3
Sample Output

1010110131
111
-1
12
21
112

  • 写回答

1条回答

  • threenewbee 2017-09-24 15:45
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器