Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <algorithm>
- using namespace std;
- ifstream fin("biminprim.in");
- ofstream fout("biminprim.out");
- int nt[5001],X=1000000000,Y=1000000000;
- struct nod
- {
- int info;
- nod * st, *dr;
- };
- void citire(nod * & p)
- {
- int x;
- fin>>x;
- if(x==0)
- p=NULL;
- else
- {
- p=new nod;
- p->info=x;
- citire(p->st);
- citire(p->dr);
- }
- }
- int prim(int n)
- {
- if(n==0 || n==1)
- return 0;
- else
- if(n%2==0&&n!=2)
- return 0;
- else
- for(int d=3;d*d<=n;d=d+2)
- if(n%d==0)
- return 0;
- return 1;
- }
- void preordine(nod * p)
- {
- if(p)
- {
- if(p->info<Y&&prim(p->info))
- Y=p->info;
- preordine(p->st);
- preordine(p->dr);
- }
- }
- void stergeTot(nod * & p)
- {
- if(p!=NULL)
- {
- stergeTot(p->st);
- stergeTot(p->dr);
- delete p;
- p=NULL;
- }
- }
- int main()
- {
- nod * p = NULL;
- citire(p);
- preordine(p->st);
- if(Y==1000000000)
- X=-1;
- else
- X=Y;
- Y=1000000000;
- preordine(p->dr);
- if(Y==1000000000)
- Y=-1;
- fout<<X<<' '<<Y;
- stergeTot(p);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement