Cod sursa(job #68704)

Utilizator mariusdrgdragus marius mariusdrg Data 29 iunie 2007 11:20:20
Problema Rsir Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.29 kb
#include<stdio.h>



int t1;
int t0;
int a;
int b;
int x;
int y;
int z;
int n;
int m;
int t21;
int t11;
int t22;
int t12;
int move1;


inline int
 sqr(int i)
{
        return i * i;
}

void trans(int &p1,int &p2)
{
        int aux = p1;
        p1 = p2;
        p2 = (a * sqr(aux) + b * sqr(p2) + x * aux + y * p2 + z) % m;
}


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);
        t21 = t0;
        t22 = t1;
        t11 = t0;
        --n;
        t12 = t1;
        while(t12 != t22 || t11 != t21 || move1 == 0)
        {
                trans(t11,t12);
                move1++;
                if (move1 == n)
                {
                        printf("%d\n",t12);
                        return 0;
                }
                trans(t21,t22);
                trans(t21,t22);
        }
        n -= move1;
        move1 = 0;
        while(t12 != t22 || t11 != t21 || move1 == 0)
        {

                trans(t11,t12);
                move1++;
        }
        n %= move1;
        while(n)
        {
                trans(t11,t12);
                --n;
        }
        printf("%d\n",t12);
        return 0;
}