Pagini recente » Cod sursa (job #499958) | Cod sursa (job #2926389) | Cod sursa (job #1309559) | Cod sursa (job #2890323) | Cod sursa (job #1066758)
#include <iostream>
#include <fstream>
using namespace std;
fstream fin("iepuri.in", ios::in);
fstream fout("iepuri.out", ios::out);
int fib(int x, int y, int z, int a, int b, int c, int n)
{
int anteprec, med, prec;
anteprec = x;
med = y;
prec = z;
for(int j = 3; j <= n; j++)
{
z = anteprec*c + med*b + prec*a;
anteprec = med;
med = prec;
prec = z;
}
return z;
}
int main()
{
int t, x, y, z, a, b, c, n;
fin>>t;
for(int i = 1; i<=t; i++)
{
fin>>x>>y>>z>>a>>b>>c>>n;
fout<<fib(x, y, z, a, b, c, n)<<endl;
}
}