fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define rep(i,a,n) for(int i=a;i<n;i++)
  4. #define per(i,a,n) for(int i=n-1;i>=a;i--)
  5. #define VI vector<int>
  6. #define PII pair<int,int>
  7. #define pb push_back
  8. #define mp make_pair
  9. #define fi first
  10. #define se second
  11. #define ll long long
  12. #define db double
  13. #define all(x) (x).begin(),(x).end()
  14. #define sz(x) ((int)x.size())
  15. mt19937 mrand(random_device{}());
  16. const ll mod = 1000000007;
  17. int rnd(int x){return mrand()%x;}
  18. clock_t ac; double TLE(){return (double)(clock()-ac)/CLOCKS_PER_SEC;}
  19. void DBG() {cerr << "]" << endl;}
  20. template<class H, class... T> void DBG(H h, T... t) {
  21. cerr << to_string(h);
  22. if(sizeof...(t)) cerr << ", ";
  23. DBG(t...);}
  24. #ifdef _DEBUG
  25. #define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
  26. #else
  27. #define dbg(...) 0
  28. #endif
  29.  
  30. vector<int> SieveOfEratosthenes(int n)
  31. {
  32. VI v;
  33. bool prime[n+1];
  34. memset(prime, true, sizeof(prime));
  35. for (int p=2; p*p<=n; p++)
  36. {
  37. if (prime[p] == true)
  38. {
  39. for (int i=p*p; i<=n; i += p)
  40. prime[i] = false;
  41. }
  42. }
  43. for (int p=2; p<=n; p++)
  44. if (prime[p])
  45. v.pb(p);
  46. return v;
  47. }
  48. int main(){
  49. ios::sync_with_stdio(0);
  50. cin.tie(0);
  51. int n;
  52. cin>>n;
  53. int a[n];
  54. for(int i=0;i<n;i++){
  55. cin>>a[i];
  56. }
  57. int k=0;
  58. int count=0;
  59. int mx = *max_element(a,a+n);
  60. VI v = SieveOfEratosthenes(mx);
  61. for(int y : v){
  62. int c=0;
  63. for(int i=0;i<n;i++){
  64. if(a[i]%y==0)c++;
  65. }
  66. if(c>count){
  67. count =c;
  68. k=y;
  69. }
  70. }
  71. cout<<k<<" "<<count<<"\n";
  72.  
  73. }
Runtime error #stdin #stdout 0s 4400KB
stdin
Standard input is empty
stdout
Standard output is empty