【题目链接】

点击打开链接

【算法】

矩阵乘法快速幂,即可

【代码】

#include<bits/stdc++.h>
using namespace std; int a,b,n; struct Matrix
{
int mat[][];
} ans;
inline void multipy(Matrix &a,Matrix b)
{
int i,j,k;
Matrix ans;
ans.mat[][] = ans.mat[][] = ans.mat[][] = ans.mat[][] = ;
for (i = ; i <= ; i++)
{
for (j = ; j <= ; j++)
{
for (k = ; k <= ; k++)
{
ans.mat[i][j] = (ans.mat[i][j] + a.mat[i][k] * b.mat[k][j]) % ;
}
}
}
a = ans;
}
inline Matrix power(Matrix a,int n)
{
Matrix ans,b = a;
ans.mat[][] = ; ans.mat[][] = ;
ans.mat[][] = ; ans.mat[][] = ;
while (n)
{
if (n & ) multipy(ans,b);
n >>= ;
multipy(b,b);
}
return ans;
}
int main()
{ while (scanf("%d%d%d",&a,&b,&n) != EOF)
{
if (!a && !b && !n) break;
if (n <= )
{
printf("%d\n",);
continue;
}
ans.mat[][] = a; ans.mat[][] = b;
ans.mat[][] = ; ans.mat[][] = ;
ans = power(ans,n-);
printf("%d\n",(ans.mat[][]+ans.mat[][])%);
} return ; }

【HDU 1005】 Number Sequence的更多相关文章

  1. 【HDU 6299】Balanced Sequence

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 我们贪心地把每一个括号序列能匹配都按照栈的规则都匹配出来. (直接递增匹配对数*2就可以了 最后栈里面就只剩下类似))))((((( ...

  2. 【HDU - 1560】DNA sequence (dfs+回溯)

    DNA sequence 直接中文了 题目描述 21世纪是生物科技飞速发展的时代.我们都知道基因是由DNA组成的,而DNA的基本组成单位是A,C,G,T.在现代生物分子计算中,如何找到DNA之间的最长 ...

  3. 【HDU 5647】DZY Loves Connecting(树DP)

    pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...

  4. 【HDU 5145】 NPY and girls(组合+莫队)

    pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...

  5. 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题

    [HDU  3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...

  6. -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】

    [把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...

  7. 【HDU 2196】 Computer(树的直径)

    [HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...

  8. 【HDU 2196】 Computer (树形DP)

    [HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...

  9. HDU - 1711 A - Number Sequence(kmp

    HDU - 1711 A - Number Sequence   Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1 ...

随机推荐

  1. [Python3网络爬虫开发实战] 3.3-正则表达式

    本节中,我们看一下正则表达式的相关用法.正则表达式是处理字符串的强大工具,它有自己特定的语法结构,有了它,实现字符串的检索.替换.匹配验证都不在话下. 当然,对于爬虫来说,有了它,从HTML里提取想要 ...

  2. 开发基本的php框架

    github路径:https://github.com/zhengchuzhou/easyPhpFramework 一.目录结构及用途 二.相关代码: 1.入口文件(index.php): <? ...

  3. 等待某(N)个线程执行完再执行某个线程的几种方法(Thread.join(),CountDownLatch,CyclicBarrier,Semaphore)

    1.main线程中先调用threadA.join() ,再调用threadB.join()实现A->B->main线程的执行顺序 调用threadA.join()时,main线程会挂起,等 ...

  4. winform消息提示框

    摘自:http://www.cnblogs.com/risen/archive/2008/01/15/1039751.html public partial class AlertForm : For ...

  5. jQuery中四个绑定事件的区别 on,bind,live,delegate

    1.jQ操作DOM元素的绑定事件的四种方式       jQ中提供了四种事件监听方式,bind.live.delegate.on,对应的解除监听的函数分别是unbind,die,undelegate, ...

  6. 动态创建div(鼠标放上显示二维码)

    最近的微信大行其道.各个网站上都给出的微信验证码,进行手机扫描加入. 怎么创建类似与点击鼠标弹出一个浮动的div显示二维码的这种效果. 1.首先制作好这样的图片,写css样式 <style ty ...

  7. jquery如何通过ajax请求获取后台数据显示在表格上

    1.引入bootstrap和jquery的cdn <link rel="stylesheet" type="text/css" href="ht ...

  8. Big String(poj 2887)

    题意: 给你一个不超过1e6的字符串,和不超过2000次的操作 操作分为两种: 1.将一个字符插入到某个位置的前面 2.询问当前位置的字符 /* 块状链表模板水题(我的智商也就能做这种题了). 观察题 ...

  9. 接龙游戏(codevs 1051)

    1051 接龙游戏  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 给出了N个单词,已经按长度排好了序 ...

  10. 【git】Git 提示fatal: remote origin already exists 错误解决办法

    今天使用git 添加远程github仓库的时候提示错误:fatal: remote origin already exists. 最后找到解决办法如下: 1.先删除远程 Git 仓库 $ git re ...