Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define nmax 2005
  3. #define valmax 3505
  4.  
  5. using namespace std;
  6.  
  7. ifstream fin ("divmax.in");
  8. ofstream fout ("divmax.out");
  9.  
  10. short int n, x, maxim;
  11. pair <short int, short int> f[valmax];
  12. vector <short int> maxdiv;
  13.  
  14. int putere( int p)
  15. {
  16. int rez = 1;
  17. while ( p-- )
  18. rez *= 10;
  19. return rez;
  20. }
  21.  
  22. bool cmp (int a, int b)
  23. {
  24. int ca = a, cb = b, ka = 0, kb = 0;
  25. while ( ca/=10 )
  26. ka++;
  27. while ( cb/=10 )
  28. kb++;
  29. while ( a/putere(ka)%10 == b/putere(kb)%10 && ka >= 1 && kb >= 1 )
  30. {
  31. ka--;
  32. kb--;
  33. }
  34. return a/putere(ka)%10 > b/putere(kb)%10;
  35. }
  36.  
  37. void ciur( int lim )
  38. {
  39. for ( int i = 2; i <= (int)sqrt(lim); ++i )
  40. if ( !f[i].first )
  41. {
  42. f[i].second = i;
  43. for ( int j = 2*i; j <= lim; j += i )
  44. f[j] = {1, i};
  45. }
  46. }
  47.  
  48. int main()
  49. {
  50. ios::sync_with_stdio(false);
  51. cin.tie(NULL); cout.tie(NULL);
  52. ciur(3500);
  53. fin>>n;
  54. for ( int i = 1; i <= n; ++i )
  55. {
  56. fin>>x;
  57. maxdiv.push_back(f[x].second);
  58. maxim = max(f[x].second, maxim);
  59.  
  60. }
  61. fout<<maxim<<'\n';
  62. sort(maxdiv.begin(), maxdiv.end(), cmp);
  63. for ( int i = 0; i < maxdiv.size(); ++i )
  64. fout<<maxdiv[i];
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement