Advertisement
a53

FirstPrime_Of

a53
Mar 24th, 2020
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. /// Solutie - Moca Andrei - 100p
  2. #include <bits/stdc++.h>
  3. namespace FastRead {
  4. const int Dim(5000);
  5. char ibuf[Dim];
  6. int ipos, ilen;
  7. char nc()
  8. {
  9. if (ipos == ilen)
  10. {
  11. ipos = 0;
  12. ilen = fread(ibuf, 1, Dim, stdin);
  13. if (!ilen) return EOF;
  14. }
  15. return ibuf[ipos++];
  16. }
  17. template<class T> void read(T& x)
  18. {
  19. char ch;
  20. int sgn = 1;
  21. while (!isdigit(ch = nc()))
  22. if (ch == '-')
  23. sgn = -1;
  24. x = ch - '0';
  25. while (isdigit(ch = nc()))
  26. x = x * 10 + (ch - '0');
  27. x *= sgn;
  28. }
  29. }
  30. using namespace FastRead;
  31. using namespace std;
  32. const int N(1e8);
  33. int lp[N + 1];
  34. vector<int> pr;
  35. int n, x, to;
  36. int64_t res;
  37. int main()
  38. {
  39. for (int i = 3; i <= N; i += 2) {
  40. if (lp[i] == 0) {
  41. lp[i] = i;
  42. pr.emplace_back(i);
  43. }
  44. to = min(N / i, lp[i]);
  45. for (int j = 0; j < static_cast<int>(pr.size()) && pr[j] <= to; ++j)
  46. lp[i * pr[j]] = pr[j];
  47. }
  48. read(n);
  49. for (int i = 1; i <= n; ++i) {
  50. read(x);
  51. if (x % 2 == 0 && x > 1)
  52. res += 2;
  53. else res += lp[x];
  54. }
  55. cout << res;
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement