程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程解疑 >> lines-Self-Replicating Numbers

lines-Self-Replicating Numbers

編輯:編程解疑
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

最佳回答:


http://www.2cto.com/kf/201303/199070.html

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved