编程介的小学生 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 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献