3 Star 14 Fork 6

徒步天下 / 程序设计与算法一OpenJudge题解

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
035:Pell数列.md 993 Bytes
一键复制 编辑 原始数据 按行查看 历史
徒步天下 提交于 2017-09-14 11:04 . 更新 035:Pell数列.md

035:Pell数列

总时间限制: 3000ms 内存限制: 65536kB

描述

输入图片说明

输入

第1行是测试数据的组数n,后面跟着n行输入。每组测试数据占1行,包括一个正整数k (1 ≤ k < 1000000)。

输出

n行,每行输出对应一个输入。输出应是一个非负整数。

样例输入

2
1
8

样例输出

1
408

全局题号

1788

题解

#include <cstdio>
#include <iostream>

using namespace std;

int pell(int n)
{
    int a=1, b=2, c;
    if (n==1)
        return a;
    if (n==2)
        return b;
    while (n>2)
    {
        c= (2*b+a)%32767;
        a=b;
        b=c;
        n--;
    }
    return b;
}

int main()
{
    int n, m;
    cin >> n;
    for (int i=0;i<n;i++)
    {
        cin >> m;
        cout << pell(m) <<endl;
    }
    return 0;
}
C++
1
https://gitee.com/se17a/c01.git
git@gitee.com:se17a/c01.git
se17a
c01
程序设计与算法一OpenJudge题解
master

搜索帮助