Skip to content

Instantly share code, notes, and snippets.

@dbc2201
Created December 6, 2018 09:25
Show Gist options
  • Select an option

  • Save dbc2201/15a8a3df3a076f2936187378b595aae8 to your computer and use it in GitHub Desktop.

Select an option

Save dbc2201/15a8a3df3a076f2936187378b595aae8 to your computer and use it in GitHub Desktop.
A program in C to find out the largest prime factor of a number
#include <stdio.h>
#include<math.h>
long long m(long long n)
{
long long max=-1;
while(n%2==0)
{
max=2;
n/=2;
}
for(int i=3;i<=sqrt(n);i+=2)
while(n%i==0)
{
max=i;
n/=i;
}
if(n>2)
max=n;
return max;
}
int main()
{
long long n;
printf("Enter a number:\n");
scanf("%lld",&n);
// n=600851475143;
printf("%lld\n",m(n));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment