Last active
August 29, 2015 14:09
-
-
Save anuradhawick/5e4d47ec2d9781aaf6cf to your computer and use it in GitHub Desktop.
Euler 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
typedef int bool; | |
#define true 1 | |
#define false 0 | |
void main(){ | |
long long int i,n=600851475143; | |
for(i=1;i<(int)sqrt(n)+1;i++){ | |
if(n%i==0 && prime(i)==1){ | |
printf("%d\n",i); | |
} | |
} | |
} | |
bool prime(long long int n){ | |
long long int i; | |
if(n<=0 || n==1 || (n%2==0 && n!=2)){ | |
return false; | |
} | |
else if(n==2 || n==3){ | |
return true; | |
} | |
for(i=3;i<(int)sqrt(n)+1;i=i+2){ | |
if(n%i==0) return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment