/home/toolbox/public_html/solutions/119/11934/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 #include <ctype.h>
10
11 #define TRUE (1 == 1)
12 #define FALSE (1 != 1)
13
14 #define DEBUG if (FALSE)
15
16 /*
17 * Author: Isaac Traxler
18 * Date: 2022-08-24
19 * Purpose: fun
20 * Problem: 11934 - Magic Formula
21 */
22
23 /*
24 * This template reads data until a terminating value is reached.
25 */
26
27 /* (a*x^2 + b*x + c ) % d == 0 over domain of 1..limit */
28
29 int a;
30 int b;
31 int c;
32 int d;
33 int limit;
34
35 void init()
36 {
37 /* FUNCTION init */
38 } /* FUNCTION init */
39
40 void dump()
41 {
42 /* FUNCTION dump */
43 } /* FUNCTION dump */
44
45 int getInput()
46 {
47 /* FUNCTION getInput */
48 int dataReadFlag;
49
50 scanf(" %d %d %d %d %d ", &a, &b, &c, &d, &limit);
51 dataReadFlag = (0 != a) || (0 != b) || (0 != c) || (0 != d) || (0 != limit);
52 return (dataReadFlag);
53 } /* FUNCTION getInput */
54
55 void process()
56 {
57 /* FUNCTION process */
58 int cnt = 0;
59 int i;
60 int tmp;
61
62 for (i=0; limit>=i; i++)
63 {
64 /* for */
65 tmp = ((a * i * i) + (b * i) + c) % d;
66 if (0 == tmp)
67 {
68 cnt++;
69 }
70 } /* for */
71 printf("%d\n", cnt);
72 } /* FUNCTION process */
73
74 int main()
75 {
76 /* main */
77 int moreToDo;
78
79 init();
80 moreToDo = getInput();
81 while (moreToDo)
82 {
83 /* while */
84 process();
85 moreToDo = getInput();
86 } /* while */
87
88 return EXIT_SUCCESS;
89 } /* main */
90