1166 D
The meaning of problems
We say that a sequence \ (X \) (length \ (n-\) ) is \ (m-cute \) if and only if \ (x_i = x_ {i - 1} + x_ {i - 2} + \ x_1 + + r_i DOTS (. 1 \ Le r_i \ Le m) \) . Now given \ (x \) of the first term and last term and \ (m \) , and asked whether there is a legitimate \ (x \) . There is also a need to construct. \ ((x_1, x_n, m \ le 10 ^ {14}) \)
Example
input
2
5 26 2
3 9 1
output
4 5 6 13 26
-1
solution
First assumes that all \ (= r_i. 1 \) , was calculated \ (n-\) , then add up one by one from left to right
Code
#include<bits/stdc++.h>
using namespace std;
const int maxn=53;
long long a[maxn],c[maxn],s,t,m;
int n;
void calcn(){
n=2;
long long sum=s;
a[1]=s;
while(1){
a[n]=sum+1;
if(a[n]>t)break;
sum+=a[n];
n++;
}
n--;
}
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%lld%lld%lld",&s,&t,&m);
calcn();
for(int i=1;i<=n;i++)c[i]=0;
long long x=t-a[n],y,k;
for(int i=2;i<=n&&x>0;i++){
k=(i==n?1:1ll<<(n-i-1));
y=min(m-1,x/k);
x-=y*k;
c[i]+=y;
}
long long sum=s;
a[1]=s;
for(int i=2;i<=n;i++){
a[i]=sum+1+c[i];
sum+=a[i];
}
if(a[n]==t){
printf("%d ",n);
for(int i=1;i<=n;i++)printf("%lld ",a[i]);
puts("");
}
else puts("-1");
}
return 0;
}