11 u, d: array [1..2000] of int;
\r
12 currentTestNumber: int;
\r
14 procedure writeTest();
\r
20 inc(currentTestNumber);
\r
21 writeln('Writing test ', currentTestNumber, '... (n = ', n, ' m = ', m, ')');
\r
22 rewrite(fp, chr(ord('0') + (currentTestNumber div 10)) + '' + chr(ord('0') + (currentTestNumber mod 10)));
\r
24 writeln(fp, n, ' ', m);
\r
26 writeln(fp, u[i], ' ', d[i]);
\r
31 function calcAnswer(n, m, u, d: int): int;
\r
36 a := (n * d) div (u + d) + 1;
\r
38 result := a * u - b * d;
\r
41 { Generates random test with n = nn, m = mm and with answer = answer }
\r
42 procedure genRandomTest(nn, mm: int; answer: int);
\r
44 i, cur, curAnswer: int;
\r
49 while (true) do begin
\r
50 curAnswer := 2000000000;
\r
51 for i := 1 to m do begin
\r
53 while (true) do begin
\r
54 u[i] := 1 + random(1000);
\r
55 d[i] := 1 + random(1000);
\r
56 cur := calcAnswer(n, m, u[i], d[i]);
\r
57 if (cur >= answer) then
\r
60 curAnswer := min(curAnswer, cur);
\r
62 if (curAnswer = answer) then
\r
67 procedure genMaxTest(nn, mm: int);
\r
74 for i := 1 to m do begin
\r
84 currentTestNumber := 1;
\r
85 randseed := 238578235;
\r
88 genRandomTest(1, 1, 239);
\r
90 genRandomTest(1, 1, 1000);
\r
92 genRandomTest(7, 2, 718);
\r
94 genRandomTest(13, 5, 999);
\r
96 genRandomTest(239, 15, 1);
\r
98 genRandomTest(1, 100, 566);
\r
101 // Tests with small answers
\r
102 for i := 1 to 5 do begin
\r
103 genRandomTest(1 + random(100), 1 + random(2000), i);
\r
107 // Tests with (100 <= answer <= 500)
\r
108 for i := 1 to 5 do begin
\r
109 genRandomTest(1 + random(100000), 1 + random(2000), 100 + random(401));
\r
111 genRandomTest(1 + random(100), 1 + random(2000), 100 + random(401));
\r
115 // Tests with (500 <= answer <= 1000)
\r
116 for i := 1 to 5 do begin
\r
117 genRandomTest(1000000 - random(10000), 2000 - random(100), 500 + random(501));
\r
119 genRandomTest(1 + random(1000), 2000 - random(100), 500 + random(501));
\r
123 // Tests with big n, m and (1000 <= answer <= 1500)
\r
124 for i := 1 to 5 do begin
\r
125 genRandomTest(1000000 - random(10000), 2000 - random(100), 1000 + random(501));
\r
129 // Tests with big n, m and answer > 1600
\r
130 for i := 1 to 5 do begin
\r
131 genRandomTest(1000000 - random(1000), 2000 - random(100), 1600 + random(301));
\r
135 // Tests with big n, m and answer
\r
136 genRandomTest(1000000, 2000, 1952);
\r
138 genRandomTest(1000000, 2000, 1963);
\r
140 genRandomTest(1000000, 2000, 1974);
\r
142 genRandomTest(1000000, 2000, 1982);
\r
144 genRandomTest(1000000, 2000, 1990);
\r
146 genMaxTest(1000000, 2000);
\r