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