二分贪心10
来源:互联网 发布:朋友圈推广软件 编辑:程序博客网 时间:2024/06/04 01:13
Description
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.
Input
The 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.
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.
Output
Output one line for each test case, that is, the K-th number module (%) 200907.
Sample Input
21 2 3 51 2 4 5
Sample Output
516
给出一个数列的前三个数,不是等差就是等比数列,再求出数列的第K个数,数字大,快速幂取模这个题一直WA,没有通过
- #include<stdio.h> 网上一位大佬的
- #include<string.h>
- #include<math.h>
- #define M 200907
- int main(){
- int T;
- scanf("%d",&T);
- while(T--){
- __int64 a,b,c;
- __int64 k;
- __int64 m=0;
- __int64 l=1,r=1;//必须全部为__int64,不然就错
- scanf("%I64d %I64d %I64d %I64d",&a,&b,&c,&k);
- if((b-a)==(c-b)){
- m=(c+((k-3)%M)*((c-b)%M))%M;
- }
- else{
- m=a%M;
- k=k-1;
- l=(c/b)%M;
- while(k){
- if(k&1){//奇数
- r=r*l%M;
- k--;
- }
- else{
- if(k==2)
- k=0;
- else
- k=k>>1;
- l=l*l%M;
- }
- }
- }
- printf("%I64d\n",m*r*l%200907);
- }
- return 0;
- }
这个是出现错误的代码
#include <iostream>#include<string.h>using namespace std;int a[3],s=200907;long long pow(long long q,int n){ long long ans=a[0]; n=n-1; while (n!=0) { if(n%2==1) { ans=((ans%s)*(q%s))%s; } n/=2; q=((q%s)*(q%s))%s; } return ans%s;}int main(){ int n,t; int ans; cin>>t; while(t--) { cin>>a[0]>>a[1]>>a[2]>>n; if(a[0]+a[2]==2*a[1]) { int d=a[2]-a[1]; ans=(a[0]+(n-1)*d%s)%s; cout<<ans<<endl; } else { long long q=a[2]/a[1]; ans=pow(q,n); cout<<ans<<endl; } } return 0;}
0 0
- 二分贪心10
- 二分+贪心
- 贪心 + 二分
- 贪心二分
- 贪心+二分
- 贪心(bnuoj49103+二分+贪心)
- BNU 49103 贪心【二分+贪心】
- hdu pie(二分+贪心)
- POJ3497 Assemble 二分+贪心
- mysterious 二分加贪心
- HDU 3650 贪心+二分
- 11627 - Slalom (二分+贪心)
- 二分+贪心+LA3177
- hdu4004(二分+贪心)
- hdu1677(贪心+二分)
- poj2456(贪心+二分)
- poj1064(贪心+浮点二分)
- 二分+贪心(总结)
- JS 俄罗斯方块(不完美)
- 勒索(比特币)病毒的预防
- 详解OS X和iOS图像处理框架Core Image
- 设计模式之原型模式
- 古北水镇上空的夜景,怎少的了S8的“夜视仪”?
- 二分贪心10
- FZU2214 Knapsack problem--01背包
- C#中关于文件的
- Ubuntu14.04(64bit)下编译openjdk-7-jdk
- MD5Util
- leaked ServiceConnection com.baidu.location.LocationClient$1@426122f0
- BeanUtils拷贝属性容易忽视的坑
- [HTML] HTML简单实现网络测速
- Android中使用Gson解析JSON数据的两种方法