HDU 3306 Another kind of Fibonacci ---构造矩阵***
Another kind of Fibonacci
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1219 Accepted Submission(s): 466
Each test case will contain three integers , N, X , Y .
N : 2<= N <= 231 – 1
X : 2<= X <= 231– 1
Y : 2<= Y <= 231 – 1
Y : 2<= Y <= 231 – 1
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std; struct node
{
__int64 mat[][];
}M_hxl,M_tom; void make_init(__int64 x,__int64 y)
{
M_hxl.mat[][]=;
M_hxl.mat[][]=(x*x)%;
M_hxl.mat[][]=(y*y)%;
M_hxl.mat[][]=(*x*y)%; M_hxl.mat[][]=;
M_hxl.mat[][]=(x*x)%;
M_hxl.mat[][]=(y*y)%;
M_hxl.mat[][]=(*x*y)%; M_hxl.mat[][]=;
M_hxl.mat[][]=;
M_hxl.mat[][]=;
M_hxl.mat[][]=; M_hxl.mat[][]=;
M_hxl.mat[][]=x;
M_hxl.mat[][]=;
M_hxl.mat[][]=y;
} void make_first(node *cur)
{
__int64 i,j;
for(i=;i<=;i++)
for(j=;j<=;j++)
if(i==j)
cur->mat[i][j]=;
else cur->mat[i][j]=;
} struct node cheng(node cur,node now)
{
node ww;
__int64 i,j,k;
memset(ww.mat,,sizeof(ww.mat));
for(i=;i<=;i++)
for(k=;k<=;k++)
if(cur.mat[i][k])
{
for(j=;j<=;j++)
if(now.mat[k][j])
{
ww.mat[i][j]+=cur.mat[i][k]*now.mat[k][j];
if(ww.mat[i][j]>=)
ww.mat[i][j]%=;
}
}
return ww;
}
void power_sum2(__int64 n)
{
__int64 sum=;
make_first(&M_tom);
while(n)
{
if(n&)
{
M_tom=cheng(M_tom,M_hxl);
}
n=n>>;
M_hxl=cheng(M_hxl,M_hxl);
}
sum=sum+*M_tom.mat[][]+M_tom.mat[][]+M_tom.mat[][]+M_tom.mat[][];
if(sum>=)
sum=sum%;
printf("%I64d\n",sum); } int main()
{
__int64 n,x,y;
while(scanf("%I64d%I64d%I64d",&n,&x,&y)>)
{
x=x%;//防止溢出
y=y%;//防止溢出
memset(M_hxl.mat,,sizeof(M_hxl.mat));
make_init(x,y);
power_sum2(n-);
}
return ;
}
HDU 3306 Another kind of Fibonacci ---构造矩阵***的更多相关文章
- hdu 3306 Another kind of Fibonacci(矩阵高速幂)
Another kind of Fibonacci Time Limit: 3000/10 ...
- HDU 3306 Another kind of Fibonacci(快速幂矩阵)
题目链接 构造矩阵 看的题解,剩下的就是模板了,好久没写过了,注意取余. #include <cstring> #include <cstdio> #include <s ...
- HDU 3306 Another kind of Fibonacci(矩阵+ll超时必须用int&输入必须取模&M必须是int类型)
Another kind of Fibonacci [题目链接]Another kind of Fibonacci [题目类型]矩阵+ll超时必须用int&输入必须取模&M必须是int ...
- hdu 3306 Another kind of Fibonacci 矩阵快速幂
参考了某大佬的 我们可以根据(s[n-2], a[n-1]^2, a[n-1]*a[n-2], a[n-2]^2) * A = (s[n-1], a[n]^2, a[n]*a[n-1], a[n-1] ...
- hdu 1757 A Simple Math Problem (构造矩阵解决递推式问题)
题意:有一个递推式f(x) 当 x < 10 f(x) = x.当 x >= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + ...
- HDU 3306 - Another kind of Fibonacci
给你 A(0) = 1 , A(1) = 1 , A(N) = X * A(N - 1) + Y * A(N - 2) (N >= 2). 求 S(N) = A(0) 2 +A(1) 2+……+ ...
- hdu 5015 233 Matrix(构造矩阵)
http://acm.hdu.edu.cn/showproblem.php?pid=5015 由于是个二维的递推式,当时没有想到能够这样构造矩阵.从列上看,当前这一列都是由前一列递推得到.依据这一点来 ...
- HDU - 1588 Gauss Fibonacci (矩阵高速幂+二分求等比数列和)
Description Without expecting, Angel replied quickly.She says: "I'v heard that you'r a very cle ...
- HDU 1757 A Simple Math Problem 【矩阵经典7 构造矩阵递推式】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=1757 A Simple Math Problem Time Limit: 3000/1000 MS (J ...
随机推荐
- Metasploit渗透某高校域服务器
本文作者:i 春秋签约作家——shuteer 前期准备:1. 使用Veil生成免杀PAYLOAD: 2. 有一个外网IP的服务器,安装好metasploit,方便操作. 一.SHELL反弹meterp ...
- python基础知识梳理----3基本数据类型,int,bool,str ,for 循环,迭代
一:python的基本类型 1.int -----整数,主要进行数学运算 2.str -----字符串,可以保存少量数据,并进行相关操作, 3. bool ---布尔类型,判断真假 4.list ...
- 记录一次因为意外断电造成gitlab(docker容器)重启之后无法访问的问题
容器启动成功,但是处于unhealthy状态,登录界面500. docker logs gitlab 最终错误是 err="opening storage failed: open bloc ...
- js 封装trim()方法,去掉空格
<script> //定义一个对象 - 名字是$ var $$ = function() {}; //原型 $$.prototype = { $id:function(id) { retu ...
- 4、Caffe其它常用层及参数
借鉴自:http://www.cnblogs.com/denny402/p/5072746.html 本文讲解一些其它的常用层,包括:softmax_loss层,Inner Product层,accu ...
- TX2 之tensorflow环境部署
刷机jetpack3.3 首先TX2必须是3.3版本的jetpack,因为截止目前nvidia发布的tensorflow只支持3.3版本的jetpack,刷机的具体步骤可以参考NVIDIA Jetso ...
- 生成allure测试报告之后,服务器端口无法访问查看生成的report,可能是这样引起的。
1. 检查防火墙 2. 如果机器有安装ADsafe,请关闭adsafe后重试
- 终于解决了贴吧手机版的一个重大BUG
终于解决了贴吧手机版的一个重大BUG 别诧异虽然同一个域名,但是,PC 和手机打开完全不一样的体验 http://tieba.yunxunmi.com/ 吃点夜校准备做梦去!! 发现 我云贴吧 一个 ...
- C#中方法,方法声明,方法调用和方法重载!
一,定义:方法是具有名称的可执行代码块. 二,方法的声明:声明方法的语法包括以下五个部分: 1,访问权限修饰符,这个是可选的参数,默认值是私有访问private,即只能从声明它的类的内部访问. 2 ...
- mysql:服务器错误代码
服务器错误代码和消息 原文:https://dev.mysql.com/doc/refman/5.7/en/error-messages-server.html MySQL的程序有几种类型的错误信息时 ...