summaryrefslogblamecommitdiffstats
path: root/mat/euler/12/prog.c
blob: c23af4daf60a14e273f39ab5db4a82d376e5c20a (plain) (tree)






















                                                                                                
                                                                                                               








                                                                                
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main (int argc, char ** argv) {
	if (argc != 1 + 1) {
		fprintf(stderr, "uporaba: %s <stevilka>, \nprimer: %s 500\n", argv[0], argv[0]);
		return 1;
	}
	unsigned long int n = strtol(argv[1], NULL, 10);
	unsigned long long int i = 1;
	unsigned long long int j = 0;
	unsigned long long int d = 0;
	unsigned long long int s = 0; // dejansko trikotniško število.
	while (1) {
		s = s+i;
		fprintf(stderr, "\rpreizkušam število %lld ...", i);
		d = 0;
		for (j = 2; j < ceill(sqrtl(s)); j++) {
			if (s % j == 0)
				d++;
		}
		d = (d*2)+2; // dva dodamo, ker sta to število samo in 1
		if (d > n) {
			fprintf(stdout, "\rnašel %lld triangelsko število %lld z %lld delitelji\n", i, s, d);
			return 0;
		}
		i++;
		if (i <= 1) // int rollover
			break;
	}
	fprintf(stderr, "napaka. intager rollover pred najdenim rezultatom!\n");
	return 2;
}