int rand(int x, int m)
{
    return (123*x*x + 1234*x + 12345) % m;
}