Pell Sequence
/*
* PellSequence.cpp
*
* Created on: 2013-09-08 16:46
* Author: lg
* Description: a1 = 1, a2 = 2, ... , an = 2 * an − 1 + an - 2 (n > 2)
* ans = an % 32767
*/
#include <stdio.h> int PellMod(int); int main()
{
int tc, n;
scanf("%d", &tc);
while(tc--){
scanf("%d", &n);
printf("%d\n", PellMod(n));
}
return 0;
} int PellMod(int n)
{
if(n == 1) return 1;
int ans[2] = {1, 2}, j = 0;
for(int i = 2; i < n; j = 1 - j, i++){
ans[j] += 2 * ans[1 - j];
ans[j] %= 32767;
}
return ans[1 - j];
}
Pell Sequence的更多相关文章
- oracle SEQUENCE 创建, 修改,删除
oracle创建序列化: CREATE SEQUENCE seq_itv_collection INCREMENT BY 1 -- 每次加几个 STA ...
- Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等
功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...
- DG gap sequence修复一例
环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...
- Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Sequence Reconstruction 序列重建
Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...
- [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
- [LeetCode] Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列
Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ...
- [LeetCode] Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- [LeetCode] Permutation Sequence 序列排序
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
随机推荐
- Sql server 本地临时表、全局临时表的区别
创建了本地临时表#Tmp.全局临时表##Tmp: 本地临时表: 取名以#开头.如:#Tmp(会自动加上一串后缀) 只有当前的连接可以访问 连接关闭后,本地临时表自动释放 全局临时表: 取名以##开头. ...
- vscode常好用的插件以及几个快捷操作
使用方法,可以在官网中搜索需要的插件或者在VsCode的“”扩展“”中搜索需要的插件添加方法使用Ctrl+P, 输入 ext install xxxx ,搜索要安装的插件,点击安装按钮即可(各取所需插 ...
- swift VS NSObject
Any class that does not inherit from another class is known as a base class. Swift classes do not in ...
- context switch
In computing, a context switch is the process of storing and restoring the state (more specifically, ...
- Springboot + SLF4j + Log4j2 打印异常日志时,耗时要5-6秒
1.使用jps -l 查看springboot项目的进程ID 2.使用命令jstack -l 进程ID > log.txt 打印堆栈信息到文件,内容如下: "http-nio-8065 ...
- 01网页<head></head>常用标记及属性
网页<head></head>常用标记及属性 <!DOCTYPE html> <html> <head> <!--网页标题--> ...
- Python 字符串常见的用法
line = “ni hao wo jiao key” line.capotalize()#首字母大写 line.center(20)#居中显示固定的字符 line.count('n')#计数,计算该 ...
- [转载] Linux Futex的设计与实现
Linux Futex的设计与实现 引子 在编译2.6内核的时候,你会在编译选项中看到[*] Enable futex support这一项,上网查,有的资料会告诉你"不选这个内核不一定能正 ...
- sql学习笔记:表的运算
在MICK的<SQL基础教程>里读到的一章,写的很好,之前很乱的思路变清晰了很多.简单来说,表的运算主要是两种:列的运算和行的运算. 表的加减法 这里是对表的列操作(向下扩展).因此,按照 ...
- 51nod 1241 特殊的排序
[题解] 设满足前后两个元素之差为1的最长上升子序列LIS的长度为m,那么本题的答案即为n-m. 证明: 1,n-m次移动一定可以让序列递增.设LIS的第一个数为i,最后一个数为j,我们按照i-1到1 ...