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$处理,容易想到用矩阵 ...
随机推荐
- [itint5]交替字符串
http://www.itint5.com/oj/#17 DP.注意曾经把赋值写成了==,结果出错半天. bool isInterleaving(string &str1, string &a ...
- [itint5]完全二叉树节点个数的统计
http://www.itint5.com/oj/#4 这题是利用完全二叉树的性质计算节点数目.那么是通过比较左右子树的最左结点的高度来看那边是满的,然后递归计算. //使用getLeftChildN ...
- JVM运行机制
JVM启动流程
- P114、面试题17:合并两个排序的链表
题目:输入两个递增排序的链表,合并这两个链表并使新链表中的结点仍然是按照递增顺序的.struct ListNode{ int m_nKey; ListNode* m_p ...
- 分布式搜索Elasticsearch——QueryBuilders.matchPhrasePrefixQuery
注:该文项目基础为分布式搜索Elasticsearch——项目过程(一)和分布式搜索Elasticsearch——项目过程(二),项目骨架可至这里下载. ES源代码中对matchPhrasePrefi ...
- Ubuntu 安装Android Studio与使用手册
用的是Ubuntu 12.04 1.先去下载,国内可以去这里下载 https://github.com/inferjay/AndroidDevTools 2.下载后解压进入android-studio ...
- IMX51启动模式
相关链接: http://blog.csdn.net/kickxxx/article/details/7236040 http://blog.csdn.net/evilcode/article/det ...
- xcopy 复制了0个文件
xcopy /Y "..\..\..\SolutionItems\zbmyuncore.db" "..\ZITaker" 复制zbmyuncore.db文件的时 ...
- Zookeeper运维经验
转自:http://www.juvenxu.com/2015/03/20/experiences-on-zookeeper-ops/ ZooKeeper 是分布式环境下非常重要的一个中间件,可以完成动 ...
- gdb调试SAPI方式的php
一.修改php-fpm.conf文件 /usr/local/php/etc/php-fpm.conf pm.max_children = 1 #只产生一个进程,便于追踪 二.得到进行服务的进程号 [r ...