blob: 753b1fb0bbdf8dd85b13c40bf53ee93e17cb1820 (
plain) (
tree)
|
|
#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;
}
|