Advertisement
edutedu

vr 28 pr4

Dec 4th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int primul(int a)
  5. {
  6. for( int i=2; i<=a; i++)
  7. if(a%i==0)
  8. return i;
  9. }
  10. int main()
  11. {
  12. int x, max=0, i, n, a[6], j, b, ct=0,c;
  13. cin>>x;
  14. cout<<"Cel mai mic divizor al nr a este: "<<primul(x)<<endl;
  15. cin>>n;
  16. for(i=0; i<n; i++)
  17. cin>>a[i];
  18. for(i=0; i<n; i++)
  19. {
  20. b=a[i]/primul(a[i]);
  21. c=b;
  22. for(j=1; j<=b; j++)
  23. if(b%j==0)
  24. ct++;
  25. if(a[i]==primul(a[i])*c && a[i]>max && ct==2)
  26. max=a[i];
  27. ct=0;
  28.  
  29. }
  30.  
  31. if(max!=0)
  32. cout<<"DA"<<" "<<max;
  33. else
  34. cout<<"NU";
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement