[HDU6198]number number number
题目大意:
给定一个数k表示你可以从包括0的斐波那契数列中任取k个数,得到它们的和。求最小的不能得到的自然数。
思路:
打表找规律,可以发现答案为f(2k+3)-1,然后用公式f(i)=f(i/2)*f((i+1)/2-1)+f(i/2+1)*f(x+1)/2)。当然也可以用矩阵快速幂。
#include<cstdio>
#include<cctype>
#include<ext/hash_map>
inline int getint() {
char ch;
while(!isdigit(ch=getchar()));
int x=ch^'';
while(isdigit(ch=getchar())) x=(((x<<)+x)<<)+(ch^'');
return x;
}
const int mod=;
__gnu_cxx::hash_map<int,int> f;
int fib(const int x) {
if(!x) return ;
if(x==||x==) return ;
if(int t=f[x]) {
return t;
} else {
return f[x]=((long long)fib(x/)*fib((x+)/-)%mod+(long long)fib(x/+)*fib((x+)/)%mod)%mod;
}
}
int main() {
for(int T=getint();T;T--) {
printf("%d\n",(fib(+getint()*)+mod-)%mod);
}
return ;
}
[HDU6198]number number number的更多相关文章
- [ActionScript 3.0] 用TextField的方法getCharIndexAtPoint(x:Number, y:Number):int实现文字在固定范围内显示
有时候我们遇到一行文字过多时必须固定文字的显示范围,但由于中英文所占字节数不一样,所以不能很好的用截取字符的方式去统一显示范围的大小,用TextField的getCharIndexAtPoint(x: ...
- 【leetcode】Single Number && Single Number II(ORZ 位运算)
题目描述: Single Number Given an array of integers, every element appears twice except for one. Find tha ...
- 4.Single Number && Single Number (II)
Single Number: 1. Given an array of integers, every element appears twice except for one. Find that ...
- leetCode191/201/202/136 -Number of 1 Bits/Bitwise AND of Numbers Range/Happy Number/Single Number
一:Number of 1 Bits 题目: Write a function that takes an unsigned integer and returns the number of '1' ...
- [LeetCode#136, 137]Single Number, Single Number 2
The question: Single Number Given an array of integers, every element appears twice except for one. ...
- [Locked] Strobogrammatic Number & Strobogrammatic Number II & Strobogrammatic Number III
Strobogrammatic Number A strobogrammatic number is a number that looks the same when rotated 180 deg ...
- Single Number,Single Number II
Single Number Total Accepted: 103745 Total Submissions: 218647 Difficulty: Medium Given an array of ...
- Ugly Number,Ugly Number II,Super Ugly Number
一.Ugly Number Write a program to check whether a given number is an ugly number. Ugly numbers are po ...
- Square Number & Cube Number
Square Number: Description In mathematics, a square number is an integer that is the square of an in ...
- leetcode@ [136/137] Single Number & Single Number II
https://leetcode.com/problems/single-number/ Given an array of integers, every element appears twice ...
随机推荐
- sru源码--language model
import sys import os import argparse import time import random import math import numpy as np import ...
- ubuntu网络连接:Ifupdown(eth0)的连接不能修改或删除
今天其实遇到了三个问题,一个是ubuntu系统上的网络图标不见了,把网络图标弄出来以后有无法联网,联网成功却变成Ifupdown(eth0)的连接且不能修改或删除. 这里我只记录最后一个问题,前两个问 ...
- 13-6_mysql索引_1_Mysql_Learning_Notes_20180719_13-6
mysql索引_1_Mysql_Learning_Notes 二分查找/折半查找法,binary search 一种在有序数组中查找某一特定元素的搜索算法; 二分查找法的优点是比较少次数,查找速度快, ...
- 002_Linux-Memory专题
一.单独查看某个进程的内存占用 pmap 736 | tail -n 1 二. 以前我对这块认识很模糊,而且还有错误的认识:今天由我同事提醒,所以我决定来好好的缕缕这块的关系. 图: -------- ...
- Mac下破解intellij IDEA 2018
一.在进入下面网站下载破解补丁 http://idea.lanyus.com/ 二.在“应用程序”中找到已经安装的IntelliJ IDEA,在app上右键,选择“显示包内容”,如下图: 将下载的破解 ...
- unity3d 材质概述 ---- shader
学习笔记: 材质概述: 物体呈现在我们前面除了形体外,还包括“固有颜色”和“质地”(质感与光学性质).固有颜色让物体的表面看起来是什么颜色,而质感决定了该物质是使用什么材质的.在三维建模软 ...
- Owin WebApi版本控制
public class WebApiControllerSelector : IHttpControllerSelector { private const string NamespaceKey ...
- tf.nn.embedding_lookup函数
tf.nn.embedding_lookup(params, ids, partition_strategy='mod', name=None, validate_indices=True, max_ ...
- java基础56 HTML5的标签知识(网页知识)
本文知识点(目录): 1.html常用标签 2.html实体标签 3.html媒体标签 4.html超链接标签 5.html图片标签 6.html标个标签 7.html框 ...
- 接口测试工具--Poster与Postman的简单实用
HTTP/SOAP协议接口的功能测试: 1.浏览器URL(GET请求) http://127.0.0.1:8000/login/?username=zhangsan&password=1234 ...