/home/toolbox/public_html/solutions/126/12665/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-10-14
18 * Purpose: fun
19 * Problem: 12665 - Joking with Fermat's Last Theorem
20 */
21
22 /*
23 * This template reads data until a terminating value is reached.
24 */
25
26 #define MAX_ULL 18446744073709551615ULL
27 #define C3 199999999900ULL
28 #define MAX 1002
29 #define mn(y) (y < MAX ? y : MAX)
30 #define NUMBER unsigned long long int
31
32 NUMBER x;
33 NUMBER y;
34 NUMBER cubes[MAX];
35
36
37 void init()
38 {
39 /* FUNCTION init */
40 int i;
41
42 for (i=0; i<MAX; i++)
43 {
44 cubes[i] = i * i * i;
45 }
46 } /* FUNCTION init */
47
48 void dump()
49 {
50 /* FUNCTION dump */
51 } /* FUNCTION dump */
52
53 int getInput()
54 {
55 /* FUNCTION getInput */
56 int dataReadFlag;
57 int tmp;
58
59 tmp = scanf(" %d %d ", &x, &y);
60 dataReadFlag = (2 == tmp);
61 return (dataReadFlag);
62 } /* FUNCTION getInput */
63
64 void process()
65 {
66 /* FUNCTION process */
67 NUMBER a;
68 NUMBER b;
69 NUMBER tmp;
70 int solutions = 0;
71 NUMBER upper;
72
73 upper = mn(y);
74 DEBUG printf("process: x = %d y = %d upper = %d\n", x, y, upper);
75 for (a=x; a<upper; a++)
76 {
77 /* For each possible starting value */
78 for (b=a+1; (b<upper) && ((C3 - cubes[a]) >= cubes[b]); b=b+2)
79 {
80 /* for each possible pairing */
81 tmp = (cubes[a] + cubes[b]);
82 DEBUG printf("\n Testing: a = %d(%d) b = %d(%d) sum = %d\n", a, cubes[a], b, cubes[b], tmp);
83 if ((3 == (tmp % 10)) && ((tmp / 10) <= y))
84 {
85 /* solution found */
86 DEBUG printf("\n a = %d(%d) b = %d(%d) sum = %d\n", a, cubes[a], b, cubes[b], tmp);
87 solutions = solutions + 2;
88 } /* solution found */
89 } /* for each possible pairing */
90 } /* For each possible starting value */
91 printf("%d\n", solutions);
92 } /* FUNCTION process */
93
94 int main()
95 {
96 /* main */
97 int moreToDo;
98 int i = 1;
99
100 init();
101 moreToDo = getInput();
102 while (moreToDo)
103 {
104 /* while */
105 printf("Case %d: ", i++);
106 process();
107 moreToDo = getInput();
108 } /* while */
109
110 return EXIT_SUCCESS;
111 } /* main */
112