编程介的小学生 2017-10-30 13:42 采纳率: 20.5%
浏览 819
已采纳

The Two Note Rag

Problem Description
Since most computers are binary machines, both powers of two and problems that involve only two values are important to computer scientists. The following problem has to do with powers of two and the digits 1 and 2.

Some powers of two as decimal values, such as 29 = 512 and 289 = 618,970,019,642,690,137,449,562,112 end in a string of digits consisting only of 1's and 2's (12 for 29 and 2112 for 289 ). In fact, it can be proved that:

For every integer R, there exists a power of 2 such that 2K uses only the digits 1 and 2 in its last R digits.

This is shown a bit more clearly in the following table:

Your job is to write a program that will determine, for given R, the smallest K such that 2K ends in a string of R digits containing only 1's and 2's.

Input
The first line of the input contains a single decimal integer, N, 1 ≤ N ≤ 50, the number of problem data sets to follow. Each data set consists of a single integer R, 1 ≤ R ≤ 20, for which we want a power of 2 ending in a string of R 1's and 2's.

Output
For each data set, you should generate one line of output with the following values: The data set number as a decimal integer (start counting at one), a space, the input value R, another space, and the smallest value K for which 2K ends in a string of R 1's and 2's.

Sample Input
6
1
2
4
5
7
15

Sample Output
1 1 1
2 2 9
3 4 89
4 5 589
5 7 3089
6 15 11687815589

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-11-23 02:30
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换