ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1041. Nikifor

what difference in this code?
Posted by Alias (Alexander Prudaev) 5 May 2007 18:42
                    for (int z = i+1; z < n; z++)
                    {
                        __int64 r = (((__int64)a[j][z])*a[d][i] - ((__int64)a[j][i])*a[d][z]);
                        a[j][z] = mod(r);
                    }
                    a[j][i] = 0;

                    for (int z = i; z < n; z++)
                    {
                        __int64 r = (((__int64)a[j][z])*a[d][i] - ((__int64)a[j][i])*a[d][z]);
                        a[j][z] = mod(r);
                    }

first get AC, but second WA9

by the way, mod(0) == 0

const int P = (1<<30)-17;

int mod(__int64 x)
{
    int r = x % P;
    if (r < 0)
        r += P;
    return r;
}

Edited by author 05.05.2007 18:49
Re: what difference in this code?
Posted by Walrus (Dmitry Bochkarev) 5 May 2007 21:09
n = 2
i = d = 0
j = 1

a:
1 1
1 1

First result:
1 1
0 0

Second result:
1 1
0 1
Re: what difference in this code?
Posted by Alias (Alexander Prudaev) 6 May 2007 13:31
thank you very much!