fork download
  1. // ~~ icebear ~~
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. typedef pair<int, int> ii;
  7. typedef pair<int, ii> iii;
  8.  
  9. template<class T>
  10. bool minimize(T &a, const T &b) {
  11. if (a > b) return a = b, true;
  12. return false;
  13. }
  14.  
  15. template<class T>
  16. bool maximize(T &a, const T &b) {
  17. if (a < b) return a = b, true;
  18. return false;
  19. }
  20.  
  21. #define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
  22. #define FORR(i,a,b) for(int i=(a); i>=(b); --i)
  23. #define REP(i, n) for(int i=0; i<(n); ++i)
  24. #define RED(i, n) for(int i=(n)-1; i>=0; --i)
  25. #define MASK(i) (1LL << (i))
  26. #define BIT(S, i) (((S) >> (i)) & 1)
  27. #define mp make_pair
  28. #define pb push_back
  29. #define fi first
  30. #define se second
  31. #define all(x) x.begin(), x.end()
  32. #define task "coprime"
  33.  
  34. const int MOD = 1e9 + 7;
  35. const int inf = 1e9 + 27092008;
  36. const ll INF = 1e18 + 27092008;
  37. const int N = 1e5 + 5;
  38. const ll primes[] = {2, 3, 5, 7, 11};
  39. const int MAX = MASK(5);
  40. int n;
  41. ll a[N];
  42. vector<ll> compress;
  43. int ft[MAX][N];
  44.  
  45. void update(int t, int x, int val) {
  46. for(; x <= n; x += x & -x) maximize(ft[t][x], val);
  47. }
  48.  
  49. int get(int t, int x) {
  50. int ans = 0;
  51. for(; x; x -= x & -x) maximize(ans, ft[t][x]);
  52. return ans;
  53. }
  54.  
  55. void init(void) {
  56. cin >> n;
  57. FOR(i, 1, n) cin >> a[i], compress.pb(a[i]);
  58. sort(all(compress));
  59. compress.resize(unique(all(compress)) - compress.begin());
  60. }
  61.  
  62. void process(void) {
  63. int res = 0;
  64. FOR(i, 1, n) {
  65. int mask = 0, mx = 0;
  66. REP(j, 5) if (a[i] % primes[j] == 0)
  67. mask |= MASK(j);
  68. mask = (MAX - 1) ^ mask;
  69. int p = upper_bound(all(compress), a[i]) - compress.begin();
  70. for(int msk = mask; msk; msk = (msk - 1) & mask)
  71. maximize(mx, get(msk, p - 1));
  72. update((MAX - 1) ^ mask, p, mx + 1);
  73. maximize(res, mx + 1);
  74. }
  75. cout << res;
  76. }
  77.  
  78. int main() {
  79. ios_base::sync_with_stdio(0);
  80. cin.tie(0); cout.tie(0);
  81. if (fopen(task".inp", "r")) {
  82. freopen(task".inp", "r", stdin);
  83. freopen(task".out", "w", stdout);
  84. }
  85. int tc = 1;
  86. // cin >> tc;
  87. while(tc--) {
  88. init();
  89. process();
  90. }
  91. return 0;
  92. }
  93.  
  94.  
Success #stdin #stdout 0.01s 5596KB
stdin
Standard input is empty
stdout
Standard output is empty