summaryrefslogblamecommitdiffstats
path: root/inf/liga/2.c
blob: 25ccbe59ce99aad46a6355bcbdb79ce8e8a9c116 (plain) (tree)





















































































































                                                                                                         
#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;
}
clau