2013 ACM-ICPC长沙赛区全国邀请赛So Easy! && 2015 ACM/ICPC Asia Regional Shenyang Online-Best Solver
2015-10-02 11:00
585 查看
<span style="background-color: transparent; color: rgb(124, 169, 237); font-family: Arial; font-size: 18px;">So Easy!</span>
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
4
那么用矩阵快速幂就可以了,代码如下:
Best Solver
Problem DescriptionThe so-called best problem solver can easily solve this problem, with his/her childhood sweetheart.
It is known that y=(5+26√)1+2x.
For a given integer x (0≤x<232) and
a given prime number M (M≤46337),
print [y]%M.
([y] means
the integer part of y)
Input
An integer T (1<T≤1000),
indicating there are T test
cases.
Following are T lines,
each containing two integers x and M,
as introduced above.
Output
The output contains exactly T lines.
Each line contains an integer representing [y]%M.
Sample Input
7 0 46337 1 46337 3 46337 1 46337 21 46337 321 46337 4321 46337
Sample Output
Case #1: 97 Case #2: 969 Case #3: 16537 Case #4: 969 Case #5: 40453 Case #6: 10211 Case #7: 17947
此题的a、b完全满足上题的要求,可用与上题完全相同的思路求解,唯一的不同点即为时向下取整而非向上取整,那么,在上题的答案基础上,减一,就是此题的答案。
还有就是指数太大,要找到循环节,其实由于mod小,循环节并没有太大,是可以搞的。
代码如下:
相关文章推荐
- 查询比本部门平均工资高的员工信息
- 自己用C语言写PIC16单片机的serial bootloader
- 博客11:开机启动过程以及相关的grub的相关知识
- HttpClient客户端
- 驱动开发(2)第一个NT驱动和NT驱动的编译
- HDU2883 kebab(中等) [最大流]判断满流(数据离散化)
- 渣滓一样的页面
- 前端素材汇总(持续更新中......)
- 查询与159号员工的工资,职位都相同的员工信息
- 黑天鹅笔记
- 仿QQ5.0侧边栏(拖拽,动画)
- 图片拉伸:resizableImageWithCapInsets
- 模式识别经典算法——FCM图像聚类分割(最简matlab实现)
- json解析
- hadoop namenode无法启动,提示Failed on local exception的解决方法
- HAXM VT-X (与Hype-V冲突)
- 论信息系统的项目范围管理
- java.lang.Exception: 索引中丢失 IN 或 OUT 参数::2 解决方法
- HDU 3819 A and B Problem
- 解决maven项目出现Dynamic Web Module 3.0 requires Java 1.6 or newer.错误