Advertisement
nicuvlad76

Untitled

Nov 19th, 2020
490
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 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;
  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.             if(Max<x) { Max=x;ct=1;}
  23.             else if(x==Max) ct++;
  24.  
  25.         }
  26.     }
  27.     cout<<Max<<' '<<ct;
  28.     return 0;
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement