Skip to content

Instantly share code, notes, and snippets.

@anuradhawick
Last active August 29, 2015 14:09
Show Gist options
  • Save anuradhawick/5e4d47ec2d9781aaf6cf to your computer and use it in GitHub Desktop.
Save anuradhawick/5e4d47ec2d9781aaf6cf to your computer and use it in GitHub Desktop.
Euler 3
#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