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$处理,容易想到用矩阵 ...
随机推荐
- undefined与null的区别---js
不错... http://www.ruanyifeng.com/blog/2014/03/undefined-vs-null.html
- C++常用语法
unordered_map<int, Node*> mp; if (mp.find(key) == mp.end()) unordered_map<int, Node*>::i ...
- javeWeb常用快捷键 Junit for changeableargs enumn reflect
*1 工具常用的快捷键 1) Eclipse和MyEclipse,IBM,2001,Java编写,开源,跨平台跨语言 2)Alt+/快速内容提示 3)Ctrl+1快速修补错误 4)Syso ...
- JXL读取Excel日期时间不准确
XL读取Excel日期时间多出了8个小时. Cell c = rs.getCell(j, i); if (c.getType() == CellType.DAT ...
- 函数buf_LRU_search_and_free_block
/******************************************************************//** Try to free a replaceable bl ...
- poj3281
非常非常经典的构图 有二分图学习基础的话,很容易想到这是一个“三分图”的匹配问题 我们将牛,food,drink作为点 为了方便,我们将牛放在中间,每头牛的出边指向drink种类,入边由food指入 ...
- BZOJ_1019_[SHOI2008]_汉诺塔_(DP)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1019 汉诺塔游戏,但是有移动优先级,在不违反原有规则的情况下,给定优先移动目标.求完成游戏所需 ...
- C++学习笔记:指向函数的指针
#include <stdio.h> int sum(int a, int b) { return a+b; } int minus(int a, int b) { return a-b; ...
- CSS3实现jquery的特效
实现 “慕课网” 的图片滑过缩放的效果 技术点:css3—— -webkit-transform:scale(1.2); .course-list-img .img_1:hover{ -webki ...
- Spring Bean之间的关系
bean之间的关系:继承和依赖继承bean的配置 Spring允许继承bean的配置,被继承的bean称为父bean,继承这个父bean的bean称为子bean 子bean从父bean中继承配置,包括 ...