编程介的小学生 2019-05-22 10:25 采纳率: 20.5%
浏览 327

分段函数的数值计算问题,怎么运用的C语言的程序代码编写思想去实现的思路做法?

Problem Description
CodeFamer is developing a game which is called Door Game(DG). In this game, player is expected to open some doors to win the game. There is a problem on each door, if player can give correct answer to the problem then the door will open. In a certain door, there are two integers n and k. There are some words on the door, it says:

F(n)={nifn<=1F(n−1)+F(n−2)otherwise,S(n)=∑i=0nDS(F(i)%F(k)) .

DS(x) means the digit sum of x. For example DS(0)=0,DS(1)=1,DS(10254)=1+0+2+5+4=12. If you can calculate S(n), the door will open, then you can advance to the next door.

In order to check play’s answer, CodeFamer should write a program to generate the right answer. However he is busy in designing the UI, so he wants you to help him to write the program.

Here is your task, when given certain n and k, you should calculate S(n).

Input
There are multiple test cases. In the first line of the input file there is an integer T indicates the number of test cases.

In the next T lines, each line contains n and k which were mentioned above.

[Technical Specification]

All input items are integers.

1<= T <= 60000

0<=n<=100000000000000 (1e14)

1 <= K <= 1000

Output
For each case,the output should occupies exactly one line. The output format is Case #id: ans, here id is the data number starting from 1; ans is the result you are expected to output.

See the sample for more details.

Sample Input
2
2 2
3 5

Sample Output
Case #1: 0
Case #2: 4

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥20 Python安装cvxpy库出问题
    • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
    • ¥15 python天天向上类似问题,但没有清零
    • ¥30 3天&7天&&15天&销量如何统计同一行
    • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
    • ¥15 C#调用python代码(python带有库)
    • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
    • ¥15 活动选择题。最多可以参加几个项目?
    • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
    • ¥15 vs2019中数据导出问题