poj 3641 快速幂
来源:互联网 发布:淘宝店铺运营费用 编辑:程序博客网 时间:2024/06/16 11:02
Xinlv wrote some sequences on the paper a long time 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.InputThe first line contains an integer N, indicting that 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. OutputOutput one line for each test case, that is, the K-th number module (%) 200907.Sample Input21 2 3 51 2 4 5Sample Output516
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;typedef long long ll;const int mod=200907;ll quick_mod(ll a,ll b) { ll ans=1; while(b) { if(b&1) ans=(ans*a)%mod; a=(a*a)%mod; b>>=1; } return ans;}int main() { int t; scanf("%d",&t); while(t--) { ll a,b,c,k; scanf("%lld%lld%lld%lld",&a,&b,&c,&k); if(2*b==a+c) { ll d=(b-a); ll ans=(a%mod+(k-1)*(b-a)%mod)%mod; printf("%lld\n",ans); } else { ll q=b/a; ll ans=(a*quick_mod(q,k-1))%mod; printf("%lld\n",ans); } } return 0;}
阅读全文
0 0
- POJ-----3641快速幂
- POJ 3641 快速幂
- poj 3641 快速幂
- poj 3641 快速幂
- POJ 3641 质数+快速幂
- poj 3641 Pseudoprime numbers 【快速幂】
- POJ 3641 - Pseudoprime numbers(快速幂)
- Pseudoprime numbers(POJ-3641)(快速幂)
- POJ 3641 -- 快速幂运算,素数判定
- POJ 3641 Pseudoprime numbers(快速幂+素数)
- POJ 3641 Pseudoprime numbers【素数+快速幂】
- POJ 3641 快速幂+素数判断
- POJ 3641 Pseudoprime numbers (快速幂)
- POJ:3641 Pseudoprime numbers(快速幂)
- poj-3641-Pseudoprime numbers【快速幂】
- POJ 3641 Pseudoprime numbers 【快速幂】
- poj 3641 Pseudoprime numbers 快速幂算法
- POJ 3641 Pseudoprime numbers (快速幂)
- 连工厂模式都不知道,别说你会设计模式
- 普通用户非root可以使用wireshark
- http://blog.csdn.net/wangdingqiaoit/article/details/8673926
- POJ 3349 简单hash
- 贪心的奇巧淫技-Join the Strings
- poj 3641 快速幂
- 深入剖析ConcurrentHashMap(2)
- NOI同步赛体验记
- rpc远程调用的简单实现
- 树状数组好题(codeforces828E)
- 新的一天开始了
- 关于防重提交
- win10设置环境变量
- string indices must be integers --GP调用执行Python时报错