Advertisement
programusy

Untitled

Mar 16th, 2023
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <string>
  5. #include <sstream>
  6.  
  7. using namespace std;
  8.  
  9. bool isPrime(int n) {
  10. if (n <= 1) {
  11. return false;
  12. }
  13. for (int i = 2; i * i <= n; i++) {
  14. if (n % i == 0) {
  15. return false;
  16. }
  17. }
  18. return true;
  19. }
  20.  
  21. int main() {
  22. ifstream file("/Users/jacobe/Desktop/liczby.rtf");
  23. string line;
  24. while (getline(file, line)) {
  25. stringstream ss(line);
  26. int n;
  27. ss >> n;
  28. if (n <= 4) {
  29. continue;
  30. }
  31. vector<int> primes;
  32. for (int i = 2; i <= n/2; i++) {
  33. if (isPrime(i) && isPrime(n - i)) {
  34. primes.push_back(i);
  35. primes.push_back(n - i);
  36. break;
  37. }
  38. }
  39. if (primes.size() == 2) {
  40. cout << n << " = " << primes[0] << " + " << primes[1] << endl;
  41. }
  42. }
  43. return 0;
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement