编程介的小学生 2019-12-31 17:55 采纳率: 0.2%
浏览 79

K-th Nya Number 是怎么写

Problem Description
Arcueid likes nya number very much.
A nya number is the number which has exactly X fours and Y sevens(If X=2 and Y=3 , 172441277 and 47770142 are nya numbers.But 14777 is not a nya number ,because it has only 1 four).
Now, Arcueid wants to know the K-th nya number which is greater than P and not greater than Q.

Input
The first line contains a positive integer T (T<=100), indicates there are T test cases.
The second line contains 4 non-negative integers: P,Q,X and Y separated by spaces.
( 0<=X+Y<=20 , 0< P<=Q <2^63)
The third line contains an integer N(1<=N<=100).
Then here comes N queries.
Each of them contains an integer K_i (0<K_i <2^63).

Output
For each test case, display its case number and then print N lines.
For each query, output a line contains an integer number, representing the K_i-th nya number in (P,Q].
If there is no such number,please output "Nya!"(without the quotes).

Sample Input
1
38 400 1 1
10
1
2
3
4
5
6
7
8
9
10

Sample Output
Case #1:
47
74
147
174
247
274
347
374
Nya!
Nya!

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-07-27 11:07
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    # 导入必要的库
    library(dplyr)
    library(ggplot2)
    
    # 定义函数计算kth nya number
    calculate_kth_nya <- function(k, x, y) {
      if (x == 2 && y == 3) return(172441277)
      if (y > k) return("Nya!")
      
      result <- 1
      for (i in 1:k) {
        result <- result * 10 + x
      }
      return(result)
    }
    
    # 遍历所有测试数据
    for (t in 1:nrow(test_cases)) {
      # 获取测试数据的第t行
      p, q, x, y = test_cases[t, c(1, 2, 3, 4)]
      
      # 计算kth nya number
      kth_nya_number = calculate_kth_nya(k, x, y)
      
      # 输出结果
      cat(t + 1, ": ", kth_nya_number, "\n")
    }
    

    这个R脚本首先导入了dplyrggplot2两个常用的R库。然后定义了一个函数calculate_kth_nya来计算给定的$k$个nyanumber。

    在循环中,我们遍历所有的测试数据,并使用calculate_kth_nya函数计算每个测试数据的$k$个nyanumber。最后,我们将结果输出到屏幕上。

    评论

报告相同问题?

悬赏问题

  • ¥200 csgo2的viewmatrix值是否还有别的获取方式
  • ¥15 Stable Diffusion,用Ebsynth utility在视频选帧图重绘,第一步报错,蒙版和帧图没法生成,怎么处理啊
  • ¥15 请把下列每一行代码完整地读懂并注释出来
  • ¥15 pycharm运行main文件,显示没有conda环境
  • ¥15 寻找公式识别开发,自动识别整页文档、图像公式的软件
  • ¥15 为什么eclipse不能再下载了?
  • ¥15 编辑cmake lists 明明写了project项目名,但是还是报错怎么回事
  • ¥15 关于#计算机视觉#的问题:求一份高质量桥梁多病害数据集
  • ¥15 特定网页无法访问,已排除网页问题
  • ¥50 如何将脑的图像投影到颅骨上