hdoj 2817 A sequence of numbers【快速幂】
A sequence of numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4384 Accepted Submission(s):
1374
ago, they might be arithmetic or geometric sequences. The numbers are not very
clear now, and only the first three numbers of each sequence are recognizable.
Xinlv wants to know some numbers in these sequences, and he needs your
help.
there are N sequences. Each of the following N lines contain four integers. The
first three indicating the first three numbers of the sequence, and the last one
is K, indicating that we want to know the K-th numbers of the
sequence.
You can assume 0 < K <= 10^9, and the other three numbers
are in the range [0, 2^63). All the numbers of the sequences are integers. And
the sequences are non-decreasing.
number module (%) 200907.
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define LL long long
#define mod 200907
using namespace std;
LL fun(LL a,LL b)
{
LL ans=1;
//a=a%mod;
while(b)
{
if(b&1)
ans=(a*ans)%mod;
b/=2;
a=(a*a)%mod;
}
return ans;
}
int main()
{
int t;
LL x,y,x1,y1;
LL a,b,c,k;
LL ans;
scanf("%d",&t);
while(t--)
{
scanf("%lld%lld%lld%lld",&a,&b,&c,&k);
if(2*b==a+c)//等差数列
printf("%lld\n",(a+(c-b)*(k-1))%mod);
else //等比数列
printf("%lld\n",(((fun((c/b),k-1))%mod)*(a%mod))%mod);
}
return 0;
}
hdoj 2817 A sequence of numbers【快速幂】的更多相关文章
- hdu 2817 A sequence of numbers(快速幂)
Problem Description Xinlv wrote some sequences on the paper a long time ago, they might be arithmeti ...
- HDU 2817 A sequence of numbers 整数快速幂
A sequence of numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- 杭电 2817 A sequence of numbers【快速幂取模】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2817 解题思路:arithmetic or geometric sequences 是等差数列和等比数 ...
- HDU 2817 A sequence of numbers
http://acm.hdu.edu.cn/showproblem.php?pid=2817 __int64 pow_mod (__int64 a, __int64 n, __int64 m)快速幂取 ...
- HDU 5667 Sequence(矩阵快速幂)
Problem Description Holion August will eat every thing he has found. Now there are many foods,but he ...
- POJ3641 Pseudoprime numbers(快速幂+素数判断)
POJ3641 Pseudoprime numbers p是Pseudoprime numbers的条件: p是合数,(p^a)%p=a;所以首先要进行素数判断,再快速幂. 此题是大白P122 Car ...
- POJ1995 Raising Modulo Numbers(快速幂)
POJ1995 Raising Modulo Numbers 计算(A1B1+A2B2+ ... +AHBH)mod M. 快速幂,套模板 /* * Created: 2016年03月30日 23时0 ...
- A - Number Sequence(矩阵快速幂或者找周期)
Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * ...
- HDU 5950 Recursive sequence(矩阵快速幂)
题目链接:Recursive sequence 题意:给出前两项和递推式,求第n项的值. 题解:递推式为:$F[i]=F[i-1]+2*f[i-2]+i^4$ 主要问题是$i^4$处理,容易想到用矩阵 ...
随机推荐
- Spring mvc 模式小结
http://www.taobaotesting.com/blogs/2375 1.spring mvc简介 Spring MVC框架是一个MVC框架,通过实现Model-View-Controlle ...
- Java在Windows的环境配置
JDK环境变量配置的步骤如下: 1.我的电脑-->属性-->高级-->环境变量. 2.配置用户变量: 系统变量 a.新建 JAVA_HOME C:\Program Files\Jav ...
- iOS开发之loadView、viewDidLoad及viewDidUnload的关系
iOS开发之loadView.viewDidLoad及viewDidUnload的关系 iOS开发之loadView.viewDidLoad及viewDidUnload的关系 标题中所说的3个方 ...
- PHP开篇之环境的搭建
PHP开篇之环境的搭建 Wamp软件下载:http://www.wampserver.com/ 此时是2.5版本 下载下来一键安装. 安装有个主意 这里先不用管 或者smtp@qq.com 13643 ...
- asp.net 母版页使用详解--转
http://www.cnblogs.com/_zjl/archive/2011/06/12/2078992.html 母版页是VS2005中新引入的一个概念,它很好地实现界面设计的模块化,并且实现实 ...
- 阿里巴巴Java面试题
研二是需要找实习的时候了,因阿里有同学内推就直接参加了电话面试,不说其他的废话直接上问题,阿里的面试官还是不错的,和蔼可亲,为人谦虚,大牛什么都懂.(投的职位是java研发)1.java中所有类的父类 ...
- HeadFirst设计模式之装饰者模式
一. 1.The Decorator Pattern attaches additional responsibilities to an object dynamically.Decorators ...
- ripple
ripple模拟器非常好用,chrome上的插件
- [HDU 1695] GCD
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- linux 读取input输入设备demo
/******************************************************************* * linux 读取input输入设备demo * 说明: * ...