B. Jzzhu and Sequences

本文介绍了一种名为B.Jzzhu的特殊序列,并提供了一个计算该序列第n项值的算法实现,输入为序列的前两项x和y,及求值的位置n,输出为序列第n项对1000000007取模后的结果。
B. Jzzhu and Sequences
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Jzzhu has invented a kind of sequences, they meet the following property:

You are given x and y, please calculate fn modulo 1000000007 (109 + 7).

Input

The first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single integer n (1 ≤ n ≤ 2·109).

Output

Output a single integer representing fn modulo 1000000007 (109 + 7).

Sample test(s)
input
2 3
3
output
1
input
0 -1
2
output
1000000006
Note

In the first sample, f2 = f1 + f33 = 2 + f3f3 = 1.

In the second sample, f2 =  - 1 - 1 modulo (109 + 7) equals (109 + 6).


#include<stdio.h>
#include<string.h>

int main()
{
    int n, m, k;
    int a[20];
    scanf("%d%d", &n, &m);
    a[1]=n;
    a[2]=m;
    scanf("%d", &k);
    for(int i=3; i<=6; i++)
    {
        a[i]=a[i-1]-a[i-2];
    }
    a[0]=a[6];
    printf("%d\n", (((a[k%6]%1000000007)+1000000007)%1000000007));
    return 0;
}
### 使用 `tf.keras.preprocessing.sequence.pad_sequences` 的方法 为了确保序列数据具有相同的长度以便于批量处理,在深度学习模型训练前通常会使用填充操作。对于 TensorFlow Keras 中的 `pad_sequences` 函数,其主要作用是对不等长的输入序列进行填充或截断,使得它们达到指定的最大长度。 此函数接受多个参数来控制如何执行填充: - **sequences**: 输入的数据列表,其中每个元素都是一个整数列表。 - **maxlen (可选)**: 所有输出序列的目标长度。如果给定,则较长的序列会被裁剪;较短的则被填充至该长度。 - **dtype (默认 'int32')**: 输出数组的数据类型。 - **padding ('pre' 或 'post')**: 当需要填充时,是在序列前面还是后面添加填充值。 - **truncating ('pre' 或 'post')**: 如果序列超过最大长度,是从哪里开始删除多的项。 - **value (默认 0.0)**: 填充所使用的具体数值[^3]。 下面是一个具体的例子展示如何应用这些设置: ```python from tensorflow.keras.preprocessing.sequence import pad_sequences texts = ['The cat sat on the mat.', 'The dog slept in the basket.'] tokenizer = keras.preprocessing.text.Tokenizer(num_words=1000) tokenizer.fit_on_texts(texts) # 将文本转换成索引序列 sequences = tokenizer.texts_to_sequences(texts) # 对序列进行填充/截到固定长度 padded_sequences = pad_sequences( sequences, maxlen=10, # 设置目标长度为10 dtype='int32', # 数据类型设为'int32' padding='post', # 在序列末端填充 truncating='post'# 超过部分从后端移除 ) print(padded_sequences) ``` 需要注意的是,在某些较高版本的 Keras/TensorFlow 中,可能需要通过导入特定包的方式来访问 `pad_sequences` 函数。例如,可以尝试如下方式引入所需功能[^4]: ```python import tensorflow as tf from tensorflow.keras.preprocessing.sequence import pad_sequences ``` 或者针对更高版本的情况: ```python from keras_preprocessing.sequence import pad_sequences ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值