fork download
  1. #include <vector>
  2. #include <list>
  3. #include <map>
  4. #include <set>
  5. #include <queue>
  6. #include <deque>
  7. #include <stack>
  8. #include <bitset>
  9. #include <algorithm>
  10. #include <functional>
  11. #include <numeric>
  12. #include <utility>
  13. #include <sstream>
  14. #include <iostream>
  15. #include <iomanip>
  16. #include <cstdio>
  17. #include <cmath>
  18. #include <cstdlib>
  19. #include <ctime>
  20. #include <climits>
  21. #include <cstring>
  22.  
  23. using namespace std;
  24.  
  25. #define mp make_pair
  26. #define pp push_back
  27. #define Sort(x) sort(x.begin(), x.end())
  28. #define rep(i, x, y) for(int i = x; i < y; ++i)
  29. #define Rep(i, x, y) for(int i = x; i <= y; ++i)
  30. #define dRep(i, x, y) for(int i = x;i >= y; --i)
  31. #define vi vector<int>
  32. #define vvi vector<vector<int> >
  33. #define ll long long
  34. #define all(v) v.begin(),v.end()
  35. #define ii pair<int, int>
  36. #define mem(x, v) memset(x, v, sizeof(x))
  37. #define nl '\n'
  38. #define MOD 1000000007
  39.  
  40. int arr[20001];
  41. vector<ll>mini;
  42. ll lcms[3][20001];
  43. ll GCD(ll x, ll y)
  44. {
  45. if(y % x == 0)
  46. return x;
  47. else
  48. return GCD(y % x, x) % MOD;
  49. }
  50.  
  51. ll LCM(ll x, ll y)
  52. {
  53. return ((x % MOD) * (y % MOD)) / GCD(x, y);
  54. }
  55.  
  56. int main()
  57. {
  58. int n, q;
  59. //freopen("input.in", "r", stdin);
  60. while(cin >> n >> q)
  61. {
  62. rep(i, 0, n)
  63. {
  64. cin >> arr[i];
  65. }
  66. mini.resize(n);
  67. Rep(i, 1, n)
  68. {
  69. rep(j, 0, n - i + 1)
  70. {
  71. if(i == 1)
  72. lcms[(i - 1 + 3) % 3][j] = arr[j];
  73. else
  74. lcms[(i - 1 + 3) % 3][j] = LCM(lcms[(i - 2 + 3) % 3][j], lcms[(i - 2 + 3) % 3][j + 1]) % MOD;
  75.  
  76.  
  77. if(!j)
  78. mini[i - 1] = lcms[(i - 1 + 3) % 3][j];
  79. else
  80. mini[i - 1] = min(mini[i - 1], lcms[(i - 1 + 3) % 3][j]);
  81. }
  82. }
  83.  
  84. int x;
  85. rep(i, 0, q)
  86. {
  87. cin >> x;
  88. cout << mini[x - 1] << nl;
  89. }
  90.  
  91.  
  92.  
  93. }
  94.  
  95. return 0;
  96. }
Success #stdin #stdout 0s 3780KB
stdin
5 5
1 2 3 4 5
1
2
3
4
5

5 5
2 3 1 4 5
1
2
3
4
5
stdout
1
2
6
12
60
1
3
6
12
60