CSUOJ 1895 Apache is late again
Description
Apache is a student of CSU. There is a math class every Sunday morning, but he is a very hard man who learns late every night. Unfortunate, he was late for maths on Monday. Last week the math teacher gave a question to let him answer as a punishment, but he was easily resolved. So the math teacher prepared a problem for him to solve. Although Apache is very smart, but also was stumped. So he wants to ask you to solve the problem. Questions are as follows:You can find a m made (1 + sqrt (2)) ^ n can be decomposed into sqrt (m) + sqrt (m-1), if you can output m% 100,000,007 otherwise output No.
Input
There are multiply cases.Each case is a line of n. (|n| <= 10 ^ 18)
Output
Line, if there is no such m output No, otherwise output m% 100,000,007.
Sample Input
2
Sample Output
9
Hint
[an an-1]T =[ (2 1) (1 0)]*[an-2 an-1]T=[(2 1) (1 0)]^n-2 *[a2 a1]
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
const int MOD = 100000007;
typedef long long ll;
struct matrix{
ll v[2][2];
matrix()
{
memset(v, 0, sizeof(v));
}
matrix operator*(const matrix &m)
{
matrix c;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
for (int k = 0; k < 2; k++)
{
c.v[i][j] += (v[i][k] * m.v[k][j]) % MOD;
}
}
}
return c;
}
};
matrix E, M, ans;
void init()
{
for (int i = 0; i < 2; i++)
E.v[i][i] = 1;
M.v[0][0] = 2; M.v[0][1] = 1;
M.v[1][0] = 1; M.v[1][1] = 0;
}
matrix quick_pow(matrix x, ll y)
{
matrix tmp = E;
while (y)
{
if (y & 1)
{
tmp =tmp* x;
y--;
}
y >>= 1;
x = x*x;
}
return tmp;
}
int main()
{
ll n;
init();
while (~scanf("%lld", &n))
{
if (n < 0)
printf("No\n");
else if (n == 0)
printf("1\n");
else if (n == 1)
printf("2\n");
else if (n == 2)
printf("9\n");
else
{
ans = quick_pow(M, n - 2);
ll a = (ans.v[0][0] * 3 + ans.v[0][1]) % MOD;
if (n & 1)
printf("%lld\n", ((a*a)%MOD + 1) % MOD);
else
printf("%lld\n", (a*a)%MOD);
}
}
return 0;
}
/**********************************************************************
Problem: 1895
User: leo6033
Language: C++
Result: AC
Time:8 ms
Memory:2024 kb
**********************************************************************/
CSUOJ 1895 Apache is late again的更多相关文章
- Why Apache Beam? A data Artisans perspective
https://cloud.google.com/dataflow/blog/dataflow-beam-and-spark-comparison https://github.com/apache/ ...
- Intra-cluster Replication in Apache Kafka--reference
Kafka is a distributed publish-subscribe messaging system. It was originally developed at LinkedIn a ...
- Apache Storm
作者:jiangzz 电话:15652034180 微信:jiangzz_wx 微信公众账号:jiangzz_wy 背景介绍 流计算:将大规模流动数据在不断变化的运动过程中实现数据的实时分析,捕捉到可 ...
- 腾讯大数据平台Oceanus: A one-stop platform for real time stream processing powered by Apache Flink
January 25, 2019Use Cases, Apache Flink The Big Data Team at Tencent In recent years, the increa ...
- Apache Beam编程指南
术语 Apache Beam:谷歌开源的统一批处理和流处理的编程模型和SDK. Beam: Apache Beam开源工程的简写 Beam SDK: Beam开发工具包 **Beam Java SDK ...
- Apache Beam: 下一代的大数据处理标准
Apache Beam(原名Google DataFlow)是Google在2016年2月份贡献给Apache基金会的Apache孵化项目,被认为是继MapReduce,GFS和BigQuery等之后 ...
- Apache Spark 2.3.0 重要特性介绍
文章标题 Introducing Apache Spark 2.3 Apache Spark 2.3 介绍 Now Available on Databricks Runtime 4.0 现在可以在D ...
- Apache和Nginx对比
面试过程中被问到Apache和Nginx服务器的对比,因为之前没有关注过这个问题,所以也没能回答上来. 今天在网上搜索资料,发现中文资料极少,还是英文资料多一下. 原文链接:https://www.w ...
- org.apache.catalina.LifecycleException异常的处理
今天调试了很久,重装tomcat都没用,后来发现是xml servlet的url-pattern的配置少写一个"/",添加后启动即可. org.apache.catalina.Li ...
随机推荐
- BZOJ1822 Frozen Nova 冷冻波
1822: [JSOI2010]Frozen Nova 冷冻波 Time Limit: 10 Sec Memory Limit: 64 MB Description WJJ喜欢“魔兽争霸”这个游戏. ...
- 【译】第十二篇 Integration Services:高级日志记录
本篇文章是Integration Services系列的第十二篇,详细内容请参考原文. 简介在前一篇文章我们配置了SSIS内置日志记录,演示了简单和高级日志配置,保存并查看日志配置,生成自定义日志消息 ...
- Anaconda3+python3环境下如何创建python2环境(win+Linux下适用,同一个anaconda下py2/3共存)
本人之前已经在anaconda环境下已经安装了python3的环境,现在因为一些需求,要安装python2环境 1.打开anaconda的anaconda prompt查看当前环境: conda in ...
- 20155303 2016-2017-2 《Java程序设计》第三周学习总结
20155303 2016-2017-2 <Java程序设计>第三周学习总结 教材学习内容总结 第四章 学会如何查询Java API文件对于Java的学习很有帮助,可以了解到如何使用各种方 ...
- 01-Coredump核心转存&&Linux程序地址分析【转】
转自:http://www.itwendao.com/article/detail/404132.html 目录(?)[-] 一Core Dump核心转存 二Linux程序地址分析 一Core Dum ...
- skb_pull skb_push skb_put
unsigned char *skb_pull(struct sk_buff *skb, int len)该函数将 data 指针向数据区的末尾移动,减少了len 字段的长度.该函数可用于从接收到的数 ...
- 安装mysql5.5的时候出现Error Nr.1045
解决办法: 1.删除注册表几个键值:HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Eventlog\Application\MySQL HKEY_L ...
- shell 指令分析nginx 日志qps
实时分析 tail -f points.api.speiyou.cn.access.log|awk 'BEGIN{key="";cnt=0}{if(key==$5){cnt++}e ...
- 【不知道是啥的NOIP模拟赛】网络入侵
题意是这样的: 给你一棵树,每个边有一个初始的0/1边权.你希望把它弄成一个给定的样子. 你每次可以选一条树链取反,然后问你最少要操作几次. ----------------------------- ...
- python类中的私有方法
假设有如下一个python类: class Foo(object): def __a(self): print "Bet you can't see me..." def bar( ...