#include #include #define B1 25 #define B2 1000 #define _DO_PRINT 0 #define _SKIP_PRINT 1 int gcd ( int a, int b ) { int r; if (a < 0) a = -a; if (b < 0) b = -b; if (a == 0) return b; if (b == 0) return a; while (b > 0) { r = a % b; a = b; b = r; } return a; } int listRatOdd ( int B, int printopt ) { int a, b, c1, c2, d; c1 = 0; if (printopt == _DO_PRINT) printf("Rational numbers <= 1\n"); for (d=0; d 1\n"); for (d=1; d 1\n"); for (s=3; s<=B; ++s) { for (a=s/2+1; a<=s; ++a) { b = s-a; if (gcd(a,b)==1) { ++c2; if (printopt == _DO_PRINT) printf("%d/%d ", a, b); if ((printopt == _DO_PRINT) && (c2 % 10 == 0)) printf("\n"); } } } if (printopt == _DO_PRINT) printf("\n"); return c1+c2; } int evenmain () { int c; c = listRatEven(B1,_DO_PRINT); printf("Bound = %d, count = %d\n", B1, c); c = listRatEven(B2,_SKIP_PRINT); printf("Bound = %d, count = %d\n", B2, c); exit(0); } int main () { char c; printf("Odd / Even : "); scanf("%c", &c); printf("%c\n", c); if ((c == 'o') || (c == 'O')) oddmain(); if ((c == 'e') || (c == 'E')) evenmain(); printf("Bad input...\n"); exit(1); } Odd / Even : o Rational numbers <= 1 1/1 0/1 1/2 2/3 3/4 4/5 5/6 6/7 7/8 8/9 9/10 10/11 11/12 12/13 13/14 14/15 15/16 16/17 17/18 18/19 19/20 20/21 21/22 22/23 23/24 24/25 1/3 3/5 5/7 7/9 9/11 11/13 13/15 15/17 17/19 19/21 21/23 23/25 1/4 2/5 4/7 5/8 7/10 8/11 10/13 11/14 13/16 14/17 16/19 17/20 19/22 20/23 22/25 1/5 3/7 5/9 7/11 9/13 11/15 13/17 15/19 17/21 19/23 21/25 1/6 2/7 3/8 4/9 6/11 7/12 8/13 9/14 11/16 12/17 13/18 14/19 16/21 17/22 18/23 19/24 1/7 5/11 7/13 11/17 13/19 17/23 19/25 1/8 2/9 3/10 4/11 5/12 6/13 8/15 9/16 10/17 11/18 12/19 13/20 15/22 16/23 17/24 18/25 1/9 3/11 5/13 7/15 9/17 11/19 13/21 15/23 17/25 1/10 2/11 4/13 5/14 7/16 8/17 10/19 11/20 13/22 14/23 16/25 1/11 3/13 7/17 9/19 11/21 13/23 1/12 2/13 3/14 4/15 5/16 6/17 7/18 8/19 9/20 10/21 12/23 13/24 14/25 1/13 5/17 7/19 11/23 13/25 1/14 2/15 3/16 4/17 5/18 6/19 7/20 8/21 9/22 10/23 11/24 12/25 1/15 3/17 5/19 9/23 11/25 1/16 2/17 4/19 7/22 8/23 1/17 3/19 5/21 7/23 9/25 1/18 2/19 3/20 4/21 5/22 6/23 7/24 8/25 1/19 5/23 7/25 1/20 2/21 3/22 4/23 5/24 6/25 1/21 3/23 1/22 2/23 4/25 1/23 3/25 1/24 2/25 1/25 Rational numbers > 1 2/1 3/2 4/3 5/4 6/5 7/6 8/7 9/8 10/9 11/10 12/11 13/12 14/13 15/14 16/15 17/16 18/17 19/18 20/19 21/20 22/21 23/22 24/23 25/24 3/1 5/3 7/5 9/7 11/9 13/11 15/13 17/15 19/17 21/19 23/21 25/23 4/1 5/2 7/4 8/5 10/7 11/8 13/10 14/11 16/13 17/14 19/16 20/17 22/19 23/20 25/22 5/1 7/3 9/5 11/7 13/9 15/11 17/13 19/15 21/17 23/19 25/21 6/1 7/2 8/3 9/4 11/6 12/7 13/8 14/9 16/11 17/12 18/13 19/14 21/16 22/17 23/18 24/19 7/1 11/5 13/7 17/11 19/13 23/17 25/19 8/1 9/2 10/3 11/4 12/5 13/6 15/8 16/9 17/10 18/11 19/12 20/13 22/15 23/16 24/17 25/18 9/1 11/3 13/5 15/7 17/9 19/11 21/13 23/15 25/17 10/1 11/2 13/4 14/5 16/7 17/8 19/10 20/11 22/13 23/14 25/16 11/1 13/3 17/7 19/9 21/11 23/13 12/1 13/2 14/3 15/4 16/5 17/6 18/7 19/8 20/9 21/10 23/12 24/13 25/14 13/1 17/5 19/7 23/11 25/13 14/1 15/2 16/3 17/4 18/5 19/6 20/7 21/8 22/9 23/10 24/11 25/12 15/1 17/3 19/5 23/9 25/11 16/1 17/2 19/4 22/7 23/8 17/1 19/3 21/5 23/7 25/9 18/1 19/2 20/3 21/4 22/5 23/6 24/7 25/8 19/1 23/5 25/7 20/1 21/2 22/3 23/4 24/5 25/6 21/1 23/3 22/1 23/2 25/4 23/1 25/3 24/1 25/2 25/1 Bound = 25, count = 400 Bound = 1000, count = 608384 Odd / Even : e Rational numbers <= 1 0/1 1/1 1/2 1/3 1/4 2/3 1/5 1/6 2/5 3/4 1/7 3/5 1/8 2/7 4/5 1/9 3/7 1/10 2/9 3/8 4/7 5/6 1/11 5/7 1/12 2/11 3/10 4/9 5/8 6/7 1/13 3/11 5/9 1/14 2/13 4/11 7/8 1/15 3/13 5/11 7/9 1/16 2/15 3/14 4/13 5/12 6/11 7/10 8/9 1/17 5/13 7/11 1/18 2/17 3/16 4/15 5/14 6/13 7/12 8/11 9/10 1/19 3/17 7/13 9/11 1/20 2/19 4/17 5/16 8/13 10/11 1/21 3/19 5/17 7/15 9/13 1/22 2/21 3/20 4/19 5/18 6/17 7/16 8/15 9/14 10/13 11/12 1/23 5/19 7/17 11/13 1/24 2/23 3/22 4/21 6/19 7/18 8/17 9/16 11/14 12/13 Rational numbers > 1 2/1 3/1 3/2 4/1 5/1 4/3 5/2 6/1 5/3 7/1 5/4 7/2 8/1 7/3 9/1 6/5 7/4 8/3 9/2 10/1 7/5 11/1 7/6 8/5 9/4 10/3 11/2 12/1 9/5 11/3 13/1 8/7 11/4 13/2 14/1 9/7 11/5 13/3 15/1 9/8 10/7 11/6 12/5 13/4 14/3 15/2 16/1 11/7 13/5 17/1 10/9 11/8 12/7 13/6 14/5 15/4 16/3 17/2 18/1 11/9 13/7 17/3 19/1 11/10 13/8 16/5 17/4 19/2 20/1 13/9 15/7 17/5 19/3 21/1 12/11 13/10 14/9 15/8 16/7 17/6 18/5 19/4 20/3 21/2 22/1 13/11 17/7 19/5 23/1 13/12 14/11 16/9 17/8 18/7 19/6 21/4 22/3 23/2 24/1 Bound = 25, count = 200 Bound = 1000, count = 304192