Advertisement
AlexAvram

Untitled

Dec 4th, 2022
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. //aceeasi functie ca la #380
  5. bool ap_prim(int a)
  6. {
  7.     short int cnt=0;
  8.     int d, pow=0;
  9.     d=2;
  10.     while (a%d==0)
  11.         a/=d, pow+=1;
  12.     if (pow>1)
  13.         return 0;
  14.     else if (pow==1)
  15.         ++cnt;
  16.     d=3;
  17.     while (a>1)
  18.     {
  19.         pow=0;
  20.         while (a%d==0)
  21.             a/=d, pow+=1;
  22.         if (pow>1)
  23.             return 0;
  24.         else if (pow==1)
  25.             ++cnt;
  26.         d+=2;
  27.         if (a>1 && d*d>a)
  28.             d=a;
  29.     }
  30.     if (cnt==2)
  31.         return 1;
  32.     else
  33.         return 0;
  34. }
  35. int main()
  36. {
  37.     short int n, cnt=0;
  38.     int nr, maxx=-1;
  39.     cin>>n;
  40.     short int i;
  41.     for (i=1; i<=n; ++i)
  42.     {
  43.         cin>>nr;
  44.         if (ap_prim(nr)==1)
  45.         {
  46.             if (nr>maxx)
  47.                 maxx=nr, cnt=1;
  48.             else if (nr==maxx)
  49.                 ++cnt;
  50.         }
  51.     }
  52.     cout<<maxx<<" "<<cnt;
  53.  
  54.     return 0;
  55. }
  56.  
Tags: prob.381
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement