/home/toolbox/public_html/solutions/3/369/a.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <stdint.h>
7 #include <math.h>
8 #include <stdlib.h>
9
10 #define TRUE (1 == 1)
11 #define FALSE (1 != 1)
12
13 #define DEBUG if (FALSE)
14
15 /*
16 * Author: Isaac Traxler
17 * Date: 2015-02-03
18 * Purpose:
19 * Problem: 369
20 */
21
22 /*
23 * This template reads data until a terminating value is reached.
24 */
25
26 int m;
27 int n;
28
29 void init()
30 {
31 /* FUNCTION init */
32 } /* FUNCTION init */
33
34 void dump()
35 {
36 /* FUNCTION dump */
37 } /* FUNCTION dump */
38
39 int getInput()
40 {
41 /* FUNCTION getInput */
42 int dataReadFlag;
43
44 scanf(" %d %d ", &n, &m);
45 dataReadFlag = (0 != m);
46 return (dataReadFlag);
47 } /* FUNCTION getInput */
48
49 void process()
50 {
51 /* FUNCTION process */
52 int numerator;
53 int denominator;
54 int i;
55 unsigned long long tot = 1;
56
57 denominator = 2;
58 numerator = m + 1;
59 while (((n-m) >= denominator) && (n >= numerator))
60 {
61 /* more to process */
62 DEBUG printf("tot=%lld num=%d den=%d\n", tot, numerator, denominator);
63 while (0 != (tot % denominator))
64 {
65 /* keep grabbing digits */
66 DEBUG printf("multiply %lld by %d\n", tot, numerator);
67 tot = tot * numerator;
68 numerator++;
69 } /* keep grabbing digits */
70 DEBUG printf("divide %lld by %d\n", tot, denominator);
71 tot = tot / denominator;
72 denominator++;
73 } /* more to process */
74 for (i=numerator; i<=n; i++)
75 {
76 tot = tot * i;
77 }
78 printf("%d things taken %d at a time is %lld exactly.\n", n, m, tot);
79 } /* FUNCTION process */
80
81 int main()
82 {
83 /* main */
84 int moreToDo;
85
86 init();
87 moreToDo = getInput();
88 while (moreToDo)
89 {
90 /* while */
91 process();
92 moreToDo = getInput();
93 } /* while */
94
95 return EXIT_SUCCESS;
96 } /* main */
97