Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- #include <sstream>
- using namespace std;
- bool isPrime(int n) {
- if (n <= 1) {
- return false;
- }
- for (int i = 2; i * i <= n; i++) {
- if (n % i == 0) {
- return false;
- }
- }
- return true;
- }
- int main() {
- ifstream file("/Users/jacobe/Desktop/liczby.rtf");
- string line;
- while (getline(file, line)) {
- stringstream ss(line);
- int n;
- ss >> n;
- if (n <= 4) {
- continue;
- }
- vector<int> primes;
- for (int i = 2; i <= n/2; i++) {
- if (isPrime(i) && isPrime(n - i)) {
- primes.push_back(i);
- primes.push_back(n - i);
- break;
- }
- }
- if (primes.size() == 2) {
- cout << n << " = " << primes[0] << " + " << primes[1] << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement