So Easy!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2026    Accepted Submission(s): 624

Problem Description
  A sequence Sn is defined as:

Where a, b, n, m are positive integers.┌x┐is the ceil of x. For example, ┌3.14┐=4. You are to calculate Sn.
  You, a top coder, say: So easy! 
 
Input
  There are several test cases, each test case in one line contains four positive integers: a, b, n, m. Where 0< a, m < 215, (a-1)2< b < a2, 0 < b, n < 231.The input will finish with the end of file.
 
Output
  For each the case, output an integer Sn.
 
Sample Input
2 3 1 2013
2 3 2 2013
2 2 1 2013
 
Sample Output
4
14
4
 
Source
 #include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef __int64 LL; LL p ;
struct Matrix
{
LL mat[][];
void init()
{
mat[][]=;mat[][]=;
mat[][]=;mat[][]=;
}
void mem(LL a,LL b)
{
mat[][]=(*a)%p; mat[][]=(b-a*a)%p;
mat[][]=; mat[][]=;
}
};
Matrix multiply(Matrix cur,Matrix ans)
{
Matrix now;
memset(now.mat,,sizeof(now.mat));
int i,j,k;
for(i=;i<=;i++)
{
for(k=;k<=;k++)
{
for(j=;j<=;j++)
{
now.mat[i][j]+=cur.mat[i][k]*ans.mat[k][j];
now.mat[i][j]%=p;
while(now.mat[i][j]<) now.mat[i][j]+=p;
}
}
}
return now;
}
void pow_mod(Matrix cur,LL n,LL a,LL b)
{
Matrix ans;
ans.init();
while(n)
{
if(n&) ans=multiply(ans,cur);
n=n>>;
cur=multiply(cur,cur);
}
LL sum=(ans.mat[][]**a+ans.mat[][]*)%p;
printf("%I64d\n",sum);
}
int main()
{
LL a,b,n;
while(scanf("%I64d%I64d%I64d%I64d",&a,&b,&n,&p)>)
{
Matrix hxl;
hxl.mem(a,b);
if(n>)
pow_mod(hxl,n-,a,b);
else printf("%I64d\n",(*a)%p);
}
return ;
}

hdu So Easy!的更多相关文章

  1. HDU 别easy在一系列的

    别easy在一系列的 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Su ...

  2. HDU 5572--An Easy Physics Problem(射线和圆的交点)

    An Easy Physics Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/ ...

  3. HDU 4359——Easy Tree DP?——————【dp+组合计数】

    Easy Tree DP? Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  4. HDU——4565So Easy!(矩阵快速幂)

    So Easy! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  5. HDU 2601An easy problem-素数的运用,暴力求解

    id=17433" target="_blank" style="color:blue; text-decoration:none">An ea ...

  6. HDU 5475An easy problem 离线set/线段树

    An easy problem Time Limit: 8000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  7. HDU 4359 Easy Tree DP?

    Easy Tree DP? Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  8. 2015 Multi-University Training Contest 6 hdu 5357 Easy Sequence

    Easy Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  9. ACM 2015年上海区域赛A题 HDU 5572An Easy Physics Problem

    题意: 光滑平面,一个刚性小球,一个固定的刚性圆柱体 ,给定圆柱体圆心坐标,半径 ,小球起点坐标,起始运动方向(向量) ,终点坐标 ,问能否到达终点,小球运动中如果碰到圆柱体会反射. 学到了向量模板, ...

随机推荐

  1. Python学习总结15:时间模块datetime & time & calendar (二)

    二 .datetime模块  1. datetime中常量 1)datetime.MINYEAR,表示datetime所能表示的最小年份,MINYEAR = 1. 2)datetime.MAXYEAR ...

  2. Java基础(42):Java中主类中定义方法加static和不加static的区别(前者可以省略类名直接在主方法调用,后者必须先实例化后用实例调用)

    package lsg.ap.april4th2; /* 知识点:1.Getter and Setter 的应用 2.局部变量与成员变量(也可叫做全局变量) 3.Static关键字的用法 a.成员变量 ...

  3. poj: 2159

    简单题,看起来很凶 #include <iostream> #include <stdio.h> #include <string> #include <st ...

  4. c++之路进阶——bzoj3343(教主的魔法)

    F.A.Qs Home Discuss ProblemSet Status Ranklist Contest ModifyUser  gryz2016 Logout 捐赠本站 Notice:由于本OJ ...

  5. hdu5322 Hope

    设dp[n]为n个数字排列时候的答案,那么可以得到dp方程 dp[n]=Σdp[n-i]*c(n-1,i-1)*(i-1)!*i^2(1<=i<=n) 然后上式可以化成卷积形式,分治FFT ...

  6. 反射认识_03_改变成员变量Fields

    包01:package ReflectionChange; public class ReflectionPoint_AB { String str1="access"; Stri ...

  7. Jquery文档接口遍历

    // children():获取所有子元素 <%@ page language="java" contentType="text/html; charset=utf ...

  8. 安装kingroot之后的残留

    /system/usr/icu/icusuflag.conf/system/usr/ikm/ikmsu/system/usr/iku//system/usr/attrch/system/etc/ins ...

  9. 12个滑稽的C语言面试问答——《12个有趣的C语言问答》评析(5)

    前文链接:http://www.cnblogs.com/pmer/archive/2013/09/17/3327262.html A,局部变量的返回地址 Q:下面的代码有问题吗?如果有,如何修改? # ...

  10. bootstrap导航条在手机上默认展开二级目录,必须用setTimeout才能实现

    bootstrap导航条在手机上默认展开二级目录,必须用setTimeout才能实现 $(document).ready(function() { $('.dropdown').hover(funct ...