题目1442:A sequence of numbers(数列计算以及二分求幂运用)
题目链接:http://ac.jobdu.com/problem.php?pid=1442
详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus
参考代码:
// // 1442 A sequence of numbers.cpp // Jobdu // // Created by PengFei_Zheng on 15/04/2017. // Copyright © 2017 PengFei_Zheng. All rights reserved. // #include <stdio.h> #include <iostream> #include <algorithm> #include <string.h> #include <cmath> #define ret 200907 using namespace std; int n; long long a,b,c,k; long long cal(long long a, long long q, long long k){ long long ans = a; k--; while(k!=0){ if(k%2==1){ ans *= q; ans%=ret; } k/=2; q*=q; q%=ret; } return ans; } int main(){ scanf("%d",&n); while(n--){ scanf("%lld%lld%lld%lld",&a,&b,&c,&k); long long ans = 0; if(b-a==c-b){ ans=( a % ret )+( ( (k-1)%ret )*( (b-a)%ret )%ret )%ret; } else{ long long q = b/a; ans = cal(a,q,k); } printf("%lld\n",ans); } return 0; } /************************************************************** Problem: 1442 User: zpfbuaa Language: C++ Result: Accepted Time:0 ms Memory:1520 kb ****************************************************************/
作者: 伊甸一点
出处: http://www.cnblogs.com/zpfbuaa/
本文版权归作者伊甸一点所有,欢迎转载和商用(须保留此段声明),且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
原文链接 如有问题, 可邮件(zpflyfe@163.com)咨询.