Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- //aceeasi functie ca la #380
- bool ap_prim(int a)
- {
- short int cnt=0;
- int d, pow=0;
- d=2;
- while (a%d==0)
- a/=d, pow+=1;
- if (pow>1)
- return 0;
- else if (pow==1)
- ++cnt;
- d=3;
- while (a>1)
- {
- pow=0;
- while (a%d==0)
- a/=d, pow+=1;
- if (pow>1)
- return 0;
- else if (pow==1)
- ++cnt;
- d+=2;
- if (a>1 && d*d>a)
- d=a;
- }
- if (cnt==2)
- return 1;
- else
- return 0;
- }
- int main()
- {
- short int n, cnt=0;
- int nr, maxx=-1;
- cin>>n;
- short int i;
- for (i=1; i<=n; ++i)
- {
- cin>>nr;
- if (ap_prim(nr)==1)
- {
- if (nr>maxx)
- maxx=nr, cnt=1;
- else if (nr==maxx)
- ++cnt;
- }
- }
- cout<<maxx<<" "<<cnt;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement