| 1 |
void abort (void); |
| 2 |
void exit (int); |
| 3 |
|
| 4 |
long long |
| 5 |
simple_rand () |
| 6 |
{ |
| 7 |
static unsigned long long seed = 47114711; |
| 8 |
unsigned long long this = seed * 1103515245 + 12345; |
| 9 |
seed = this; |
| 10 |
return this >> 8; |
| 11 |
} |
| 12 |
|
| 13 |
unsigned long long int |
| 14 |
random_bitstring () |
| 15 |
{ |
| 16 |
unsigned long long int x; |
| 17 |
int n_bits; |
| 18 |
long long ran; |
| 19 |
int tot_bits = 0; |
| 20 |
|
| 21 |
x = 0; |
| 22 |
for (;;) |
| 23 |
{ |
| 24 |
ran = simple_rand (); |
| 25 |
n_bits = (ran >> 1) % 16; |
| 26 |
tot_bits += n_bits; |
| 27 |
|
| 28 |
if (n_bits == 0) |
| 29 |
return x; |
| 30 |
else |
| 31 |
{ |
| 32 |
x <<= n_bits; |
| 33 |
if (ran & 1) |
| 34 |
x |= (1 << n_bits) - 1; |
| 35 |
|
| 36 |
if (tot_bits > 8 * sizeof (long long) + 6) |
| 37 |
return x; |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
#define ABS(x) ((x) >= 0 ? (x) : -(x)) |
| 43 |
|
| 44 |
int |
| 45 |
main (void) |
| 46 |
{ |
| 47 |
long long int i; |
| 48 |
|
| 49 |
for (i = 0; i < 10000; i++) |
| 50 |
{ |
| 51 |
unsigned long long x, y; |
| 52 |
x = random_bitstring (); |
| 53 |
y = random_bitstring (); |
| 54 |
|
| 55 |
if (sizeof (int) == sizeof (long long)) |
| 56 |
goto save_time; |
| 57 |
|
| 58 |
{ unsigned long long xx = x, yy = y, r1, r2; |
| 59 |
if (yy == 0) continue; |
| 60 |
r1 = xx / yy; |
| 61 |
r2 = xx % yy; |
| 62 |
if (r2 >= yy || r1 * yy + r2 != xx) |
| 63 |
abort (); |
| 64 |
} |
| 65 |
{ signed long long xx = x, yy = y, r1, r2; |
| 66 |
if ((unsigned long long) xx << 1 == 0 && yy == -1) |
| 67 |
continue; |
| 68 |
r1 = xx / yy; |
| 69 |
r2 = xx % yy; |
| 70 |
if (ABS (r2) >= (unsigned long long) ABS (yy) || (signed long long) (r1 * yy + r2) != xx) |
| 71 |
abort (); |
| 72 |
} |
| 73 |
save_time: |
| 74 |
{ unsigned int xx = x, yy = y, r1, r2; |
| 75 |
if (yy == 0) continue; |
| 76 |
r1 = xx / yy; |
| 77 |
r2 = xx % yy; |
| 78 |
if (r2 >= yy || r1 * yy + r2 != xx) |
| 79 |
abort (); |
| 80 |
} |
| 81 |
{ signed int xx = x, yy = y, r1, r2; |
| 82 |
if ((unsigned int) xx << 1 == 0 && yy == -1) |
| 83 |
continue; |
| 84 |
r1 = xx / yy; |
| 85 |
r2 = xx % yy; |
| 86 |
if (ABS (r2) >= (unsigned int) ABS (yy) || (signed int) (r1 * yy + r2) != xx || ((xx < 0) != (r2 < 0) && r2)) |
| 87 |
abort (); |
| 88 |
} |
| 89 |
{ unsigned short xx = x, yy = y, r1, r2; |
| 90 |
if (yy == 0) continue; |
| 91 |
r1 = xx / yy; |
| 92 |
r2 = xx % yy; |
| 93 |
if (r2 >= yy || r1 * yy + r2 != xx) |
| 94 |
abort (); |
| 95 |
} |
| 96 |
{ signed short xx = x, yy = y, r1, r2; |
| 97 |
r1 = xx / yy; |
| 98 |
r2 = xx % yy; |
| 99 |
if (ABS (r2) >= (unsigned short) ABS (yy) || (signed short) (r1 * yy + r2) != xx) |
| 100 |
abort (); |
| 101 |
} |
| 102 |
{ unsigned char xx = x, yy = y, r1, r2; |
| 103 |
if (yy == 0) continue; |
| 104 |
r1 = xx / yy; |
| 105 |
r2 = xx % yy; |
| 106 |
if (r2 >= yy || r1 * yy + r2 != xx) |
| 107 |
abort (); |
| 108 |
} |
| 109 |
{ signed char xx = x, yy = y, r1, r2; |
| 110 |
r1 = xx / yy; |
| 111 |
r2 = xx % yy; |
| 112 |
if (ABS (r2) >= (unsigned char) ABS (yy) || (signed char) (r1 * yy + r2) != xx) |
| 113 |
abort (); |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
exit (0); |
| 118 |
} |