Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FirstPrime
- /// Solutie - Moca Andrei - 100p
- #include <bits/stdc++.h>
- namespace FastRead {
- const int Dim(5000);
- char ibuf[Dim];
- int ipos, ilen;
- char nc()
- {
- if (ipos == ilen)
- {
- ipos = 0;
- ilen = fread(ibuf, 1, Dim, stdin);
- if (!ilen) return EOF;
- }
- return ibuf[ipos++];
- }
- template<class T> void read(T& x)
- {
- char ch;
- int sgn = 1;
- while (!isdigit(ch = nc()))
- if (ch == '-')
- sgn = -1;
- x = ch - '0';
- while (isdigit(ch = nc()))
- x = x * 10 + (ch - '0');
- x *= sgn;
- }
- }
- using namespace FastRead;
- using namespace std;
- const int N(1e8);
- int lp[N + 1];
- vector<int> pr;
- int n, x, to;
- int64_t res;
- int main()
- {
- for (int i = 3; i <= N; i += 2) {
- if (lp[i] == 0) {
- lp[i] = i;
- pr.emplace_back(i);
- }
- to = min(N / i, lp[i]);
- for (int j = 0; j < static_cast<int>(pr.size()) && pr[j] <= to; ++j)
- lp[i * pr[j]] = pr[j];
- }
- read(n);
- for (int i = 1; i <= n; ++i) {
- read(x);
- if (x % 2 == 0 && x > 1)
- res += 2;
- else res += lp[x];
- }
- cout << res;
- return 0;
- }
- Placinte
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long LL;
- int main() {
- LL n, k, v[32], m, cmin, cost, sum = 0;
- cin >> n >> k;
- cin >> v[0];
- for(LL i = 1; i < n; ++i) {
- cin >> v[i];
- if(v[i] > 2 * v[i-1])
- v[i] = 2 * v[i-1];
- }
- cmin = 4e18;
- for(LL i = n-1; i >= 0; --i) {
- LL need = (k >> i);
- sum += need * v[i];
- k -= (need << i);
- cmin = min(cmin, sum + (k > 0) * v[i]);
- }
- cout << cmin;
- return 0;
- }
- Fibonacci3
- #include <fstream>
- #include <vector>
- #define M 2500000000000000000
- #define P 1000009
- #define ll long long
- using namespace std;
- ifstream f("fibonacci3.in");
- ofstream g("fibonacci3.out");
- ll r, n, i, j, sol, suma, nr, t;
- ll d[30], e[30];
- vector<ll> ha[P];
- void adaug_in_hash(ll x)
- {
- r = x % P;
- ha[r].push_back(x);
- }
- void fibo_generator()
- {
- ll a, b, c;
- a = 0;
- b = 1;
- adaug_in_hash(a);
- while(a + b <= M)
- {
- c = a + b;
- a = b;
- b = c;
- adaug_in_hash(c);
- }
- }
- int main()
- {
- fibo_generator();
- f >> n;
- for(i = 1; i <= n; i++)
- f >> d[i];
- //calculez numarul submultimilor nevide
- nr = (1 << n) - 1;
- sol = 0;
- suma = 0;
- e[1] = 0;
- //generez submultimile si calculez dinamic suma elementelor
- for(i = 1; i <= nr; i++)
- {
- //adun 1 la nr binar din sirul e
- t = 1;
- j = 1;
- while(t == 1)
- {
- if(e[j]==1)
- {
- suma -= d[j];
- e[j] = 0;
- }
- else
- {
- e[j] = 1;
- suma += d[j];
- t = 0;
- }
- j++;
- }
- r = suma % P;
- for(j = 0; j < ha[r].size(); j++)
- if(suma == ha[r][j]) sol++;
- }
- g << sol;
- return 0;
- }
Add Comment
Please, Sign In to add comment