fork download
  1. /// CUSTEZ TEMPLATE ///
  2. // Satus: 23C.KIENGIANG //
  3.  
  4. #include <bits/stdc++.h>
  5. #define For(i,n,m) for(int i=n; i<=m; i++)
  6. #define ForD(i,n,m) for(int i=n; i>=m; i--)
  7. #define LLI long long int
  8. #define double long double
  9. #define INF 0x3f3f3f3f3f
  10. #define db(n) cout << (#n) << " = " << n << endl
  11. #define pb push_back
  12. #define mp make_pair
  13. #define X first
  14. #define Y second
  15. #define max3(a,b,c) max(max(a, b), c)
  16. #define max4(a,b,c,d) max(max(a, b), max(c, d))
  17. #define min3(a,b,c) min(min(a, b), c)
  18. #define min4(a,b,c,d) min(min(a, b), min(c, d))
  19. #define lwb lower_bound
  20. #define upb upper_bound
  21. #define PI 3.14159265
  22.  
  23. #define name ""
  24.  
  25. using namespace std;
  26.  
  27. typedef pair < int, int > _2i;
  28. typedef pair < int, _2i > _3i;
  29. typedef pair < _2i, _2i > _4i;
  30. typedef vector < int > _vi;
  31. typedef vector < _2i > _v2i;
  32. typedef vector < _vi > _2vi;
  33. typedef vector < _2vi > _3vi;
  34. typedef vector < _3i > _v3i;
  35. typedef vector < _v2i > _2v2i;
  36. typedef vector < _4i > _v4i;
  37.  
  38. /// Author: @CustezTruong ig: custez.tr ///
  39.  
  40. unsigned LLI n, k, kq=0;
  41. unsigned LLI x[101];
  42. unsigned LLI a[101];
  43.  
  44. void Try(int i)
  45. {
  46. for(int j=0; j<=1; j++)
  47. {
  48. x[i]=j;
  49. if (i<k) Try(i+1);
  50. else
  51. {
  52. LLI tich=1, dem=0, tbd;
  53. For(t,1,k)
  54. if (x[t]==1)
  55. {
  56. tbd=tich;
  57. tich=tich*a[t];
  58. dem++;
  59. if (tich/a[t]!=tbd || tich<tbd || tich>n)
  60. {
  61. dem=0;
  62. break;
  63. }
  64. }
  65. if (dem>0)
  66. {
  67. if (dem%2==0) kq-=n/tich;
  68. else kq+=n/tich;
  69. }
  70. }
  71. }
  72. }
  73.  
  74. void sub2()
  75. {
  76. Try(1);
  77. if (kq<=0) cout << -1;
  78. else cout << kq;
  79. }
  80.  
  81. void process()
  82. {
  83. cin >> n >> k;
  84. For(i,1,k) cin >> a[i];
  85. sub2();
  86. }
  87.  
  88. signed main()
  89. {
  90. ios_base::sync_with_stdio(false);
  91. cin.tie(0);
  92. //freopen(name".inp", "r", stdin);
  93. //freopen(name".out", "w", stdout);
  94. process();
  95. return 0;
  96. }
  97.  
  98. /*
  99.  * notes:
  100.  * #HotWheels #DevGang #Custez #CTG
  101.  * "i will try to get Corvette C8!"
  102.  * "i copied this code from the internet :))"
  103.  * END.
  104.  */
  105.  
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
-1