Cod sursa(job #180927)

Utilizator gabitzish1Gabriel Bitis gabitzish1 Data 17 aprilie 2008 17:42:57
Problema Rsir Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.44 kb
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int v,w,q,t0,t1,a,b,x,y,z,m,n,i;

int main()
{
    freopen("rsir.in","r",stdin);
    freopen("rsir.out","w",stdout);

    scanf("%d %d %d %d %d %d %d %d %d", &t0, &t1, &a, &b, &x, &y, &z, &m, &n);
    v = t0 % m, w = t1 % m;
    for (i = 2;i <= n; i++)
    {
        q = a * v * v + b * w * w + x * v + y * w + z;
        v = w, w = q % m;
    }
    printf("%d\n",w);

    return 0;
}