Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- namespace variabile {
- int n;
- bool gasit;
- } // namespace variabile
- int este_prim(int n);
- int main() {
- variabile::gasit = false;
- cout << "N: ";
- cin >> variabile::n;
- for (std::size_t aux = 2; aux <= variabile::n / 2; ++aux) {
- if (este_prim(aux)) {
- if (este_prim(variabile::n - aux)) {
- cout << variabile::n << " = " << aux << " + " << variabile::n - aux
- << endl;
- variabile::gasit = true;
- }
- }
- }
- if (!variabile::gasit)
- cout << variabile::n << " nu poate fii exprimat sub forma de 2 numere prime"
- << endl;
- // sa nu se inchida programul cand este compilat
- // in statutul de debug
- return 0;
- }
- // procedeu de verificare
- int este_prim(int n) {
- int PRIM = 1;
- for (std::size_t i = 2; i <= n / 2; ++i) {
- if (n % i == 0) {
- PRIM = 0;
- break;
- }
- }
- return PRIM;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement