Ahmed_Negm

Untitled

Mar 2nd, 2022
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.16 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3. #include<iomanip>
  4. #include<algorithm>
  5. #include<cstdlib>
  6. #include<cstring>
  7. #include<vector>
  8.  
  9. #define ll long long
  10. #define sz(x) int(x.size())
  11. using namespace std;
  12.  
  13. void Fast_IO(){
  14.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  15.     #ifndef ONLINE_JUDGE
  16.         freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  17.     #endif
  18. }
  19.  bool is_prime(int n){
  20.      if(n<2||(n %2 ==0 && n!=2)) return false;
  21.      for(int i =3; i<= sqrt(n); i+=2){
  22.          if(n%i==0) return false;
  23.      }
  24.     return true;
  25.  }
  26. int prime_count(vector<int>v, int n){
  27.     int counter =0;
  28.     for(int i =0; i<n; i++){
  29.         if(is_prime(v[i])) counter++;
  30.     }
  31.     return counter;
  32. }
  33. bool is_palindrome(int n){
  34.     string s = to_string(n);
  35.     int i =0, j=sz(s)-1;
  36.     while(i<j){
  37.         if(s[i] != s[j]) return false;
  38.     }
  39.     return true;
  40. }
  41. int count_palindrome(vector<int>v, int n){
  42.     int counter =0;
  43.     for(int i =0; i<n; i++){
  44.         if(is_palindrome(v[i])) counter++;
  45.     }
  46.     return counter;
  47. }
  48. int number_divisors(int n){
  49.     int counter =0;
  50.     for(int i =1; i<sqrt(n); i++){
  51.         if(n%i==0) counter+=2;
  52.     }
  53.     int sq= sqrt(n);
  54.     if(sq*sq==n) counter++;
  55.     return counter;
  56. }
  57. int max_divisor(vector<int>v,int n){
  58.     int max_number = -1, max_divisors = -1;
  59.     for(int i =0; i<n; i++){
  60.         int n_divisors = number_divisors(v[i]);
  61.         if(n_divisors>= max_divisors){
  62.             max_divisors= n_divisors;
  63.             max_number= v[i];
  64.         }
  65.        
  66.     }
  67.     return max_number;
  68.  
  69. }
  70.  
  71.  
  72.  
  73. void solve(){
  74.    
  75.    int n; cin>>n;
  76.    vector<int>v(n);
  77.    for(int i =0; i<n; i++) cin>>v[i];
  78.    sort(v.begin(),v.end());
  79.    cout<<"The maximum number : "<<v[n-1]<<"\n";
  80.    cout<<"The minimum number : "<<v[0]<<"\n";
  81.    cout<<"The number of prime numbers : "<<prime_count(v,n)<<"\n";
  82.    cout<<"The number of palindrome numbers : "<<count_palindrome(v,n)<<"\n";
  83.    cout<<"The number that has the maximum number of divisors : "<<max_divisor(v,n)<<"\n";
  84.  
  85.    
  86.  
  87.  
  88. }
  89.  
  90. int main(){
  91.     Fast_IO();
  92. int t =1;
  93. // cin>>t;
  94. while(t--){
  95. solve();
  96. }
  97. return 0;
  98. }  
Advertisement
Add Comment
Please, Sign In to add comment