Last active
February 10, 2026 05:11
-
-
Save dgodfrey206/927a269a57ba0b57ea31c271eb2ef69a to your computer and use it in GitHub Desktop.
The prime factors of 13195 are 5,7,13 and 29. What is the largest prime factor of the number 600851475143?
This file contains hidden or 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 <bits/stdc++.h> | |
| #include <cassert> | |
| using namespace std; | |
| using ll = long long; | |
| int sieve() { | |
| ll n = 600851475143; | |
| ll sz = sqrt(n); | |
| vector<bool> prime(sz, true); | |
| prime[1] = prime[2] = true; | |
| for (int i = 2; i < sz; i++) | |
| for (int k = i + i; k < sz; k += i) | |
| prime[k] = false; | |
| for (int i = sz - 1; i > 1; i--) | |
| if (prime[i] && n % i == 0) | |
| return i; | |
| return 1; | |
| } | |
| int main() { | |
| cout << sieve(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment