编程介的小学生 2019-12-31 18:39 采纳率: 0.2%
浏览 62

Perfect Sequence 怎么解答

Problem Description
A sequence of integers is called a perfect sequence when all the partial sums a0, a0 + a1, a0 + a1 + a2, ..., a0 + a1 + ... + an are all positive.
Letⅴs consider a specific sequence , (ai = 1 or ai = (1-m), 1 ÷ i ÷ (m*n) ) , whose total sum is 1. Actually you can easily deduce that there are n occurrences of (1-m). So how many of these sequences are perfect sequences.

Input
Input contains several testcases.
For each test case, you will be given n, m (1 ÷ m, n ÷ 100000) in a single line.
Process to the end of the file.

Output
On each single line, output a number r mod 100000007, r is the number of perfect sequences (ai = 1 or ai = (1-m), 1 ÷ i ÷ (m*n) ) .

Sample Input
4 2
5 2
3 4

Sample Output
14
42
22

  • 写回答

1条回答 默认 最新

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

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

    # 读取数据
    input <- readLines()
    
    # 解析输入
    n <- as.integer(input[1])
    m <- as.integer(input[2])
    
    # 初始化结果数组
    result <- rep(0, length(m))
    
    # 计算结果
    for (i in 1:(n-1)) {
      for (j in 1:(m-1)) {
        result[i] += factorial(i+1)*factorial(j+1)*factorial((i+j)/2)
      }
    }
    
    # 输出结果
    print(result)
    
    # 定义阶乘函数
    factorial <- function(n) {
      if (n == 0) return(1)
      else return(n * factorial(n - 1))
    }
    
    # 将结果模10^9+7进行处理
    result <- apply(result, 1, function(x) x %% 100000007)
    
    # 输出结果
    print(result)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 数据量少可以用MK趋势分析吗
  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
  • ¥15 大智慧怎么编写一个选股程序
  • ¥100 python 调用 cgps 命令获取 实时位置信息
  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
  • ¥20 ensp怎么配置让PC1和PC2通讯上
  • ¥50 有没有适合匹配类似图中的运动规律的图像处理算法
  • ¥15 dnat基础问题,本机发出,别人返回的包,不能命中