Δημοσιεύτηκε: 03 Ιούλ 2012, 11:50
από stamatiou
Μήπως έχει λύσει κανένας το 3ο σε C; Επειδή εγώ έχω κάνει αυτό:
Κώδικας: Επιλογή όλων

/*
This is the solution for the 3rd problem of the Euler Project in http://projecteuler.net/problem=3
Articulation:
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?

Solution:
This programm starts from NUMBER and checks if there is a prime divisor for it.
*/

#include <stdio.h>

#define NUMBER 600851475143LL

int is_prime(long long num);

int main(void) {

long long i;

for(i = NUMBER; i >= 2; i--) {
if(is_prime(i)) {
if( (NUMBER % i) == 0) {
printf("%lld\n", i);
return 0;
}
}
}

return 0;
}

// Generates prime numbers less or equal than limit using 0 1 and storing them in ptable
int is_prime(long long num)
{
long long i;

if(num == 2)
return 1;

for( i = 2; i < num; i++) {
if( (num % i) == 0 )
return 0;
}

return 1;
}

Και μου βγάζει έξοδο σωστή για μικρότερα νούμερα αλλά για αυτό που μας δίνει, δε μου βγαίνει ποτέ :D