编程介的小学生 2016-12-13 16:16 采纳率: 20.5%
浏览 871
已采纳

Self-Replicating Numbers

Description

Vasya's younger brother Misha is fond of playing with numbers. Two days ago he discovered that 93762 = 87909376 -- the last four digits constitute 9376 again. He called such numbers self-replicating. More precisely, an n-digit number is called self-replicating if it is equal to the number formed by the last n digits of its square. Now Misha often asks Vasya to help him to find new such numbers. To make the things worse Vasya's brother already knows what the scales of notation are, so he asks Vasya to find, forexample, hexadecimal or binary self-replicating numbers.
Vasya wants to help his brother, but unfortunately he is very busy now: he is seriously preparing and training for the next ACM Regional Contest. So he asked you to write a program that for a given base b and length n will find all n-digit self-replicating numbers in the scale of notation with base b.
Input

The only line of the input contains two numbers b and n separated by a single space, the base b of the scale of notation (2 <= b <= 36) and required length n (1 <= n <= 2000).
Output

The first line of the output contains K -- the total number of self-replicating numbers of length n in base b. Next K lines contain one n-digit number in base b each. Uppercase Latin characters from A to Z must be used to represent digits from 10 to 35 when b > 10. The self-replicating numbers can be listed in arbitrary order.
Sample Input

12 6
Sample Output

2
1B3854
A08369

  • 写回答

1条回答 默认 最新

  • threenewbee 2016-12-13 16:13
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题