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
|
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int jePrastevilo(int u) {
if (u <= 1)
return 0;
if (u == 2)
return 1;
for (int i = 2; i <= ceil(sqrt(u)); i++)
if (u % i == 0)
return 0;
return 1;
}
int main (int argc, char ** argv) {
if (argc != 1+1) {
fprintf(stderr, "uporaba: %s <stevilo>\nprimer: %s 600851475143\n", argv[0], argv[0]);
return 1;
}
unsigned long long p = 0;
unsigned long long n = strtoll(argv[1], NULL, 10);
unsigned long long i = 1;
unsigned long long k = ceil(sqrt(n))+1;
while (i < k) {
i = i + 2;
if (!jePrastevilo(i))
continue;
if (n % i == 0)
p = i;
if (1==1) {
fprintf(stderr, "%lld, i = %lld, k = %lld, n = %lld\r", (i/k)*100, i,k,n);
}
}
fprintf(stdout, "\rkonec. našel največje praštevilo %lld: %lld\n", n, p);
return 0;
}
|