Advertisement
Ahmed_Negm

Untitled

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