Advertisement
newb_ie

Untitled

Nov 25th, 2021
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2.  
  3. using namespace std;
  4.  
  5. template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a % b) : a); }
  6. template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
  7.  
  8. const int maxN = 1000; //range
  9. long long isVisited[maxN / 64 + 200];
  10. vector<int> primes;
  11. void Sieve_of_Eratosthenes() {
  12. int limit = maxN + 100;
  13. for (long long i = 3; i <= sqrt(limit) ; i += 2) {
  14. if (!(isVisited[i / 64] & (1LL << (i % 64)))) {
  15. for (long long j = i * i; j <= limit; j += 2 * i) {
  16. isVisited[j / 64] |= (1LL << (j % 64));
  17. }
  18. }
  19. }
  20. primes.push_back(2);
  21. for (long long i = 3; i <= limit; i += 2) {
  22. if (!(isVisited[i / 64] & (1LL << (i % 64)))) {
  23. primes.push_back(i);
  24. }
  25. }
  26. }
  27.  
  28. bool is_prime(int n) {
  29. if (n < 2) return false;
  30. if (n == 2) return true;
  31. if (n % 2 == 0) return false;
  32. if (!(isVisited[n / 64] & (1LL << (n % 64)))) return true;
  33. return false;
  34. }
  35.  
  36. int pf_count(int n) {
  37. int cnt = 0;
  38. for (int p : primes) {
  39. if (p * p > n) break;
  40. if (n % p == 0) {
  41. ++cnt;
  42. while (n % p == 0) n /= p;
  43. }
  44. }
  45. if (n > 1) ++cnt;
  46. return cnt;
  47. }
  48.  
  49. #include <ext/pb_ds/assoc_container.hpp>
  50. #include <ext/pb_ds/tree_policy.hpp>
  51. using namespace __gnu_pbds;
  52. typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
  53.  
  54. int main() {
  55. //~ Sieve_of_Eratosthenes();
  56. //~ int n = 10;
  57. //bool f = is_prime(n);//returns true if n is prime and returns false if n is not a prime number
  58. //cout << pf_count(n) << '\n'; //how many primes present in prime factorization of n
  59. //os.order_of_key(n) => returns counts of elements less then n
  60. //os.find_by_order(n) => nth position value
  61. //~ ordered_set os;
  62. //~ os.insert(10);
  63. //~ os.insert(20);
  64. //~ os.insert(30);
  65. //~ cout << os.order_of_key(30) << '\n';
  66. //~ cout << *os.find_by_order(2) << '\n';
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement