Pagini recente » Cod sursa (job #2496365) | Cod sursa (job #2764707) | Cod sursa (job #1124535) | Cod sursa (job #1331932) | Cod sursa (job #2812323)
#include <iostream>
#include <fstream>
#define mod 666013
#define ll long long
using namespace std;
ifstream fin("iepuri.in");
ofstream fout("iepuri.out");
int answear(int x, int y, int z, int a, int b, int c, int n)
{
int ans;
x %= mod;
y %= mod;
z %= mod;
ans = z;
n -= 2;
while(n)
{
ans = ((a * z) % mod + (b * y) % mod + (c * x) % mod) % mod;
x = y;
y = z;
z = ans;
--n;
}
return ans;
}
int main()
{
int x, y, z, a, b, c, n, t, i;
fin>>t;
for(i = 1; i <= t; ++i)
{
fin>>x>>y>>z>>a>>b>>c>>n;
fout<<answear(x, y, z, a, b, c, n)<<'\n';
}
return 0;
}