编程介的小学生 2020-01-07 00:56 采纳率: 20.5%
浏览 42

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥16 mybatis的代理对象无法通过@Autowired装填
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂
    • ¥15 wordpress 产品图片 GIF 没法显示
    • ¥15 求三国群英传pl国战时间的修改方法
    • ¥15 matlab代码代写,需写出详细代码,代价私
    • ¥15 ROS系统搭建请教(跨境电商用途)
    • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。