Skip to content

Commit

Permalink
Solution for largest prime factor
Browse files Browse the repository at this point in the history
- Changed directory.
- Changed source file from bits/stdc++ to iostream and math.h
  • Loading branch information
ademclk committed Aug 15, 2022
1 parent e4dc98f commit ed9dcb8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
28 changes: 28 additions & 0 deletions challenge/largest_prime_factor/largestprimefactor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <iostream>
#include <math.h>

using namespace std;
int main()
{
long long int n = 800851475143;
long long int max = INT_MIN;
while (n % 2 == 0)
{
max = 2;
n = n / 2;
}

for (long long int i = 3; i <= sqrt(n); i = i + 2) // i will only iterate through odd values
{
while (n % i == 0)
{
max = i;
n = n / i;
}
}
if (n > 2)
{
max = n;
}
cout << max << endl;
}
26 changes: 0 additions & 26 deletions find the largest prime factor/largestprimefactor.cpp

This file was deleted.

0 comments on commit ed9dcb8

Please sign in to comment.