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.首先通过相邻三个数字 ...
随机推荐
- WP开发笔记——WP7 SDK使用技巧
俗话说的好,工欲善其事,必先利其器. 入门WP开发之前,免不了要先接触开发环境和开发工具.使用WP7 SDK进行开发,我们需要掌握SDK的一些实用技巧,以便我们的开发. 一.开启/关闭电脑键盘输入 W ...
- JavaScript ==和===
== : 值等 === :恒等(引用等) ref: http://blog.csdn.net/wang171838/article/details/8554305 JavaScript支持“=”.“ ...
- silverlight 文本框只能输入汉字
private void txtName_KeyDown(object sender, KeyEventArgs e) { Regex rg = new Regex("^[\u4e00-\u ...
- php 文件上传类 实例分享
最近在研究php上传的内容,找到一个不错的php上传类,分享下. <?php /** * 文件上传类 * class: uploadFile * edit: www.jbxue.com */ c ...
- MVVM模式的一个小例子
使用SilverLight.WPF也有很长时间了,但是知道Binding.Command的基本用法,对于原理性的东西,一直没有深究.如果让我自己建一个MVVM模式的项目,感觉还是无从下手,最近写了一个 ...
- [Solved] install Gentoo in VBox: network interface eth0 does not exist
ERROR:interface eth0 does not exist; ensure that you have loaded the correct kernel moudle for your ...
- LAMP开发之环境搭建(2014.12.7在ubuntu下)
Ubuntu下搭建LAMP环境 前言:学习PHP脚本编程语言之前,必须先搭建并熟悉开发环境,开发环境有很多种,例如LAMP.WAMP.MAMP等.这里我搭建的是LAMP环境,即Linux.Apache ...
- C# 发邮件类可发送附件
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Ne ...
- 【nodejs】 文件系统(fs) 之读写文件
//写入文件 var data = "hello world"; fs.writeFile('c:\\a.txt', data, 'ascii', function(err) { ...
- 简单的C#线程开发实例(隔一秒改变一下Label的Text)
要实现的效果:点击按纽,窗口上的label上出现1~100数字的变化. 第一个实例(把窗口上的label上文字改成0): using System; using System.Windows.Form ...