a53

GeluI

a53
Apr 22nd, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. FirstPrime
  2. /// Solutie - Moca Andrei - 100p
  3. #include <bits/stdc++.h>
  4. namespace FastRead {
  5. const int Dim(5000);
  6. char ibuf[Dim];
  7. int ipos, ilen;
  8. char nc()
  9. {
  10. if (ipos == ilen)
  11. {
  12. ipos = 0;
  13. ilen = fread(ibuf, 1, Dim, stdin);
  14. if (!ilen) return EOF;
  15. }
  16. return ibuf[ipos++];
  17. }
  18. template<class T> void read(T& x)
  19. {
  20. char ch;
  21. int sgn = 1;
  22. while (!isdigit(ch = nc()))
  23. if (ch == '-')
  24. sgn = -1;
  25. x = ch - '0';
  26. while (isdigit(ch = nc()))
  27. x = x * 10 + (ch - '0');
  28. x *= sgn;
  29. }
  30. }
  31. using namespace FastRead;
  32. using namespace std;
  33. const int N(1e8);
  34. int lp[N + 1];
  35. vector<int> pr;
  36. int n, x, to;
  37. int64_t res;
  38. int main()
  39. {
  40. for (int i = 3; i <= N; i += 2) {
  41. if (lp[i] == 0) {
  42. lp[i] = i;
  43. pr.emplace_back(i);
  44. }
  45. to = min(N / i, lp[i]);
  46. for (int j = 0; j < static_cast<int>(pr.size()) && pr[j] <= to; ++j)
  47. lp[i * pr[j]] = pr[j];
  48. }
  49. read(n);
  50. for (int i = 1; i <= n; ++i) {
  51. read(x);
  52. if (x % 2 == 0 && x > 1)
  53. res += 2;
  54. else res += lp[x];
  55. }
  56. cout << res;
  57. return 0;
  58. }
  59.  
  60. Placinte
  61. #include <bits/stdc++.h>
  62.  
  63. using namespace std;
  64.  
  65. typedef long long LL;
  66.  
  67. int main() {
  68. LL n, k, v[32], m, cmin, cost, sum = 0;
  69. cin >> n >> k;
  70.  
  71. cin >> v[0];
  72. for(LL i = 1; i < n; ++i) {
  73. cin >> v[i];
  74. if(v[i] > 2 * v[i-1])
  75. v[i] = 2 * v[i-1];
  76. }
  77.  
  78. cmin = 4e18;
  79. for(LL i = n-1; i >= 0; --i) {
  80. LL need = (k >> i);
  81. sum += need * v[i];
  82. k -= (need << i);
  83. cmin = min(cmin, sum + (k > 0) * v[i]);
  84. }
  85.  
  86. cout << cmin;
  87. return 0;
  88. }
  89.  
  90. Fibonacci3
  91. #include <fstream>
  92. #include <vector>
  93. #define M 2500000000000000000
  94. #define P 1000009
  95. #define ll long long
  96. using namespace std;
  97. ifstream f("fibonacci3.in");
  98. ofstream g("fibonacci3.out");
  99. ll r, n, i, j, sol, suma, nr, t;
  100. ll d[30], e[30];
  101. vector<ll> ha[P];
  102.  
  103. void adaug_in_hash(ll x)
  104. {
  105. r = x % P;
  106. ha[r].push_back(x);
  107. }
  108.  
  109. void fibo_generator()
  110. {
  111. ll a, b, c;
  112. a = 0;
  113. b = 1;
  114. adaug_in_hash(a);
  115. while(a + b <= M)
  116. {
  117. c = a + b;
  118. a = b;
  119. b = c;
  120. adaug_in_hash(c);
  121. }
  122. }
  123.  
  124. int main()
  125. {
  126. fibo_generator();
  127. f >> n;
  128. for(i = 1; i <= n; i++)
  129. f >> d[i];
  130. //calculez numarul submultimilor nevide
  131. nr = (1 << n) - 1;
  132.  
  133. sol = 0;
  134. suma = 0;
  135. e[1] = 0;
  136. //generez submultimile si calculez dinamic suma elementelor
  137. for(i = 1; i <= nr; i++)
  138. {
  139. //adun 1 la nr binar din sirul e
  140. t = 1;
  141. j = 1;
  142. while(t == 1)
  143. {
  144. if(e[j]==1)
  145. {
  146. suma -= d[j];
  147. e[j] = 0;
  148. }
  149. else
  150. {
  151. e[j] = 1;
  152. suma += d[j];
  153. t = 0;
  154. }
  155. j++;
  156. }
  157. r = suma % P;
  158. for(j = 0; j < ha[r].size(); j++)
  159. if(suma == ha[r][j]) sol++;
  160. }
  161. g << sol;
  162. return 0;
  163. }
Add Comment
Please, Sign In to add comment