Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <limits>
- using namespace std;
- bool naoehprimo(int n){
- bool flag = true;
- if(n <= 1) return true;
- if(n == 2) return false;
- if(n%2 == 0) return true;
- for(int i = 3 ; i< sqrt(n); i++){
- if(n%i == 0){
- flag == false;
- return true;
- }
- else flag = true;
- }
- return(false);
- }
- int main(){
- int t;
- cin>>t;
- for(int i = 0; i < t ; i++){
- int entrada;
- cout<<"digite a entrada: ";
- cin >> entrada;
- cout<<"\n";
- if(entrada %2 == 0){
- continue;
- }
- else{
- int sol_1, sol_2;
- sol_1 = -1;
- sol_2 = sol_1;
- int distancia = numeric_limits<int>::max();
- for(int j = 2 ; j < entrada ; j++){
- if(naoehprimo(j) && naoehprimo(entrada - j)){
- int distancia_atual = abs(j - (entrada - j));
- if(distancia_atual < distancia){
- distancia = distancia_atual;
- sol_1 = j;
- sol_2 = entrada - j;
- }
- }
- }
- cout<<"essa é a soma de não primos mais proximos: "<<sol_1<<" "<<sol_2<<"\n";
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment