Advertisement
nicuvlad76

Untitled

Nov 19th, 2020
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int n,x,i,d;
  6.     int ct, Max,Min;
  7.     bool ok;
  8.     cin>>n; ///nr de elemente
  9.     ct=0;Max=-1;Min=1e9;
  10.     for(int i=1;i<=n;i++)
  11.     {
  12.         cin>>x;///valoarea citita
  13.         ok=1; /// am presuspus ca x este prim
  14.         if(x<2) ok=0;
  15.         else
  16.         {
  17.            for(d=2;d*d<=x && ok==1;d++)
  18.             if(x%d==0)ok=0;
  19.         }
  20.         if(ok==1)
  21.         {
  22.             ct++;///numara cate sunt prime
  23.             if(Max<x) Max=x;
  24.             if(Min>x) Min=x;
  25.         }
  26.  
  27.     }
  28.     cout<<ct<<' '<<Min<<' '<<Max;
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement