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 ...
随机推荐
- 知识笔记:jQuery 事件对象属性小结
使用事件自然少不了事件对象.因为不同浏览器之间事件对象的获取,以及事件对象的属性都有差异,导致我们很难跨浏览器使用事件对象.jQuery中统一了事件对象,当绑定事件处理函数时,会将jQuery格式化后 ...
- C语言的内存对齐
从一个例子开始 象下面这样定义的结构体占几个字节? typedef struct{ char a; int i; } Sample; char占1个字节,int占4个字节,答案是5个字节? 错了.如果 ...
- python变量内存地址释放与加速并行计算多线程
1.导入numba和gc包进行并行计算和内存释放 代码如下很容易的: #coding:utf-8 import time from numba import jit, prange, vectoriz ...
- app横竖屏切换
问题: 使用react编写的页面,编译后的页面文件打包成app安装后,在手机上显示时,初次横竖屏切换时会出现页面尺寸渲染问题,要跳到其它页面后才能恢复,如图: 由竖屏切换成横屏后页面出现很多空白. 解 ...
- 【译】第九篇 Replication:复制监视器
本篇文章是SQL Server Replication系列的第九篇,详细内容请参考原文. 复制监视器允许你查看复制配置组件的健康状况.这一篇假设你遵循前八篇,并且你已经有一个合并发布和事务发布.启动复 ...
- win10定时关机
CMD 输入shutdown -s -t 7200这个命令,大家可以自已设置7200这个时间,自己算一下60分钟=3600秒:
- 【codeforces】【比赛题解】#855 Codefest 17
神秘比赛,以<哈利波特>为主题……有点难. C题我熬夜切终于是写出来了,可惜比赛结束了,气啊. 比赛链接:点我. [A]汤姆·里德尔的日记 题意: 哈利波特正在摧毁神秘人的分灵体(魂器). ...
- Flip Bits
Determine the number of bits required to flip if you want to convert integer n to integer m. Notice ...
- 2015 Dhaka
2015 Dhaka A - Automatic Cheater Detection solution 模拟计数. B - Counting Weekend Days solution 模拟计数. C ...
- Flask:文件配置方式实践及其中的各种问题记录
Windows 10家庭中文版,Python 3.6.4,Flask 1.0.2, 提示: 1.请查看本文后面的“18-07-17 11:18重大纠正” ! 2.flask run命令运行时传入参数 ...