1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <unistd.h>
#include <string.h>
#define M 512
#define pedantic_fgets(a, b, c) if (!fgets(a, b, c)) { fprintf(stderr, "napaka pri vnosu\n"); return 1; }
struct p {
long long int a;
long long int b;
};
int main (void) {
char buf[M];
char * cp;
long long int m, n, s, a, b, c;
m = n = s = a = b = c = 0; /* uh */
pedantic_fgets(buf, M, stdin);
m = strtoll(buf, &cp, 10);
if (!*++cp) return 1;
n = strtoll(cp, NULL, 10);
struct p * r = calloc(M, sizeof(struct p));
int u = 0;
fprintf(stderr, "interval je [%lld; %lld]\n", m, n);
#if 0
for (a = 1; a <= n; a++)
for (b = 1; b <= n; b++)
for (c = 1; c <= n; c++) {
if (c >= m && c <= n && a*a+b*b == c*c) {
for (int i = 0; i < u; i++) {
if ((r[i].a == a && r[i].b == b)
|| (r[i].a == b && r[i].b == a)) {
#ifndef EVAL
fprintf(stderr, "ogabno\n");
#endif
goto ogabno;
}
}
r[u].a = a;
r[u++].b = b;
#ifndef EVAL
fprintf(stderr, "%lld² + %lld² = %lld²\n", a, b, c);
#endif
s++;
ogabno:;
}
}
fprintf(stdout, "%lld\n", s);
#endif
#if 0
for (int a = 1; a <= n; a++)
for (int b = a+1; b <= n; b++) { /* a < b, b < c <= pravzaprav to sploh ni res*/
for (c = b+1; c*c < a*a+b*b; c++); /* koren je počasnejši */
if (c >= m && c <= n && a*a + b*b == c*c)
s++;
}
#endif
#if 0 /* eulerjeva metoda ne generira vseh trojic */
/* a = x² - y²
b = 2xy
c = x²+y² */
#define COND (c < 100)
for (int x = 2; COND; x++) {
for (int y = 1; y < x; y++) {
c = x*x+y*y;
#ifndef EVAL
a = x*x-y*y;
b = 2*x*y;
fprintf(stderr, "%d²+%d²=%d² ", a, b, c);
#endif
if (c >= m && c <= n) {
#ifndef EVAL
fprintf(stderr, "ŠTEJEMO\n");
#endif
s++;
}
#ifndef EVAL
else {
fprintf(stderr, "NE ŠTEJEMO\n");
}
#endif
}
}
#endif
#if 0
for (a = 1; a <= n; a++)
for (b = 1; b <= n; b++) {
double e = a*a+b*b;
double d = sqrt(e);
#ifndef EVAL /* CMS compila z -DEVAL */
fprintf(stderr, "preverjam (%lld^2 + %lld^2 = %lf) = %lf^2\n", a, b, e, d);
#endif
if ((int) d >= m && (int) d <= n && d == (int) d) {
for (int i = 0; i < u; i++) {
if ((r[i].a == a && r[i].b == b)
|| (r[i].a == b && r[i].b == a)) {
#ifndef EVAL
fprintf(stderr, "ogabno\n");
#endif
goto ogabno;
}
}
r[u].a = a;
r[u++].b = b;
s++;
ogabno:;
}
}
#endif
for (a = 1; a <= n; a++)
for (b = 1; b <= n; b++)
for (c = 1; c <= n; c++)
if (a*a+b*b=c*c) {
}
fprintf(stdout, "%lld\n", s);
return 0;
}
|