2013 ACM-ICPC长沙赛区全国邀请赛——A So Easy!
这题在比赛的时候不知道怎么做,后来看了别人的解题报告,才知道公式sn=(a+sqrt(b))^n+(a-sqrt(b))^n;
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>
using namespace std;
struct ma
{
__int64 a[][];
void init()
{
a[][]=a[][]=;
a[][]=a[][]=;
}
};
int mod;
ma mul(ma a,ma b)
{
ma ans;
int i,j,k;
for(i=;i<;i++)
for(j=;j<;j++)
{
ans.a[i][j]=;
for(k=;k<;k++)
ans.a[i][j]=(ans.a[i][j]%mod+((a.a[i][k]%mod)*(b.a[k][j]%mod)%mod))%mod;
}
return ans;
}
ma pows(ma a,__int64 n)
{
ma ans;
ans.init();
while(n)
{
if(n&)
ans=mul(ans,a);
n>>=;
a=mul(a,a);
}
return ans;
}
int main()
{
int a,b,n;
__int64 sum,q,s;
while(scanf("%d%d%d%d",&a,&b,&n,&mod)!=EOF)
{
ma p,ans;
s=*a%mod;
p.a[][]=s;
p.a[][]=(b-a*a)%mod;
p.a[][]=;
p.a[][]=;
q=((*a*a)%mod+*b%mod)%mod;
ans=pows(p,n-);
sum=(((ans.a[][]%mod)*(q%mod))%mod+((ans.a[][]%mod)*(s%mod)))%mod;
if(sum<) sum=(sum+mod)%mod;
printf("%I64d\n",sum);
}
return ;
}
2013 ACM-ICPC长沙赛区全国邀请赛——A So Easy!的更多相关文章
- HDU 4573 Throw the Stones(动态三维凸包)(2013 ACM-ICPC长沙赛区全国邀请赛)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4573 Problem Description Remember our childhood? A fe ...
- 2013 ACM-ICPC长沙赛区全国邀请赛——Bottles Arrangement
这题当时竟然没看啊…… 找规律:求和m+m+m-1+m-1+……前n项 ;}
- 2013 ACM-ICPC长沙赛区全国邀请赛—Special equations
……但是没仔细看,直接跳过了 这题直接枚举就可以过了 ;}
- HDU 4571 Travel in time ★(2013 ACM/ICPC长沙邀请赛)
[题意]给定N个点,每个点有一个停留所需的时间Ci,和停留能够获得的满意度Si,有M条边,每条边代表着两个点走动所需的时间ti,现在问在规定的T时间内从指定的一点S到E能够获得的最大的满意度是多少?要 ...
- HDU 4568 Hunter(最短路径+DP)(2013 ACM-ICPC长沙赛区全国邀请赛)
Problem Description One day, a hunter named James went to a mysterious area to find the treasures. J ...
- HDU 4569 Special equations(枚举+数论)(2013 ACM-ICPC长沙赛区全国邀请赛)
Problem Description Let f(x) = anxn +...+ a1x +a0, in which ai (0 <= i <= n) are all known int ...
- HDU 4571 Travel in time(最短路径+DP)(2013 ACM-ICPC长沙赛区全国邀请赛)
Problem Description Bob gets tired of playing games, leaves Alice, and travels to Changsha alone. Yu ...
- HDU 4565 So Easy!(数学+矩阵快速幂)(2013 ACM-ICPC长沙赛区全国邀请赛)
Problem Description A sequence Sn is defined as:Where a, b, n, m are positive integers.┌x┐is the cei ...
- 2013 ACM/ICPC 长沙网络赛J题
题意:一个数列,给出这个数列中的某些位置的数,给出所有相邻的三个数字的和,数列头和尾处给出相邻两个数字的和.有若干次询问,每次问某一位置的数字的最大值. 分析:设数列为a1-an.首先通过相邻三个数字 ...
随机推荐
- 设置textview背景色为透明
UITextView *textView=[[UITextView alloc]initWithFrame:CGRectMake(20, 40, 150, 170)];//初始化并设置大小 textV ...
- vim包,已自带所有常用插件及常用命令总结
/** ****************************************************************************** * @author Maox ...
- 安装gitolite,并ssh公钥无密码登录
安装gitolite,并ssh公钥无密码登录 gitolite是管理git版本库的一种方案,它将git版本库的管理信息放在了一个特殊git版本库里.gitolite与linux操作系统集成了,需要使用 ...
- 一个JS的日期格式化算法示例
一个JS的日期格式化算法. 例子: <script> /** * Js日期格式化算法实例 * by www.jbxue.com */ function dateFormat(date, f ...
- phpcms v9 源码解析(4)content模块下的index.php文件的init()方法解析
在了解index.php中的init函数的时候,让我们先看看最开始的几行代码 1-5 第二行, defined('IN_PHPCMS') or exit('Nopermission resource ...
- objdump的使用方法和 symbol table的每列的含义
一.objdump的用法 objdump命令的man手册 objdump [-a] [-b bfname| --target=bfdname] [-C] [--debugging] ...
- 1106. Lowest Price in Supply Chain (25)
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...
- 使用PowerShell 连接Azure
除了使用门户登入外,还可以使用PowerShell的方式来连接Azure.首先要去下载组件 http://azure.microsoft.com/en-us/downloads/?rnd=1 http ...
- Oracle之存储过程
1.存储过程创建 oracle中创建存储过程的语法如下: CREATE [OR REPLACE] PROCEDURE PRO_NAME[(parameter1[,parameter2]...)]is| ...
- WPF-控件-ListView
<Window x:Class="DataTemplate2.MainWindow" xmlns="http://schemas.microsoft.com/win ...