summaryrefslogblamecommitdiffstats
path: root/mat/advent/7/prog.c
blob: 974a3909a094f7108e0a6f8685d311cc28024c9d (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

















                                                                                                

                                                   
                                    
                                                                                  








                                                                                   
#include <stdio.h>
#include <stdlib.h>
/* opozorilo za prihodnost:
 * 	to je zelo slab način za rešitev naloge. prosim, naredi mi uslugo in ga ne uporabljaj!
 * 		-- a, 2020 */
int main (int argc, char ** argv) {
	if (argc != 1+1) {
		fprintf(stderr, "uporaba: %s <številka>\nprimer: %s 300\n", argv[0], argv[0]);
		return 1;
	}
	unsigned long int b = strtol(argv[1], NULL, 10);
	unsigned long int x = b;
	unsigned long int y = x;
	unsigned long int z = x;
	unsigned long long int i = 0;
	unsigned long long int r = 0;
	unsigned long long int s = 0; /* število najdenih in zapiSanih trojk */
	for (x = b; x > 0; x--) {
		for (y = x-1; y > 0; y--) {
			for (z = y-1; z > 0; z--) {
				r++;
				/* fprintf(stderr, "%lu, %lu, %lu\n", x, y, z); */
				if ((x+y+z) % 3 == 0) {
					s++;
				}
			}
		}
	}
	fprintf(stdout, "\rkonec: našel sem skupno %llu trojk, r==%llu.\n", s, r);
	return 0;
}