Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- using namespace std;
- template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a % b) : a); }
- template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
- const int maxN = 1000; //range
- long long isVisited[maxN / 64 + 200];
- vector<int> primes;
- void Sieve_of_Eratosthenes() {
- int limit = maxN + 100;
- for (long long i = 3; i <= sqrt(limit) ; i += 2) {
- if (!(isVisited[i / 64] & (1LL << (i % 64)))) {
- for (long long j = i * i; j <= limit; j += 2 * i) {
- isVisited[j / 64] |= (1LL << (j % 64));
- }
- }
- }
- primes.push_back(2);
- for (long long i = 3; i <= limit; i += 2) {
- if (!(isVisited[i / 64] & (1LL << (i % 64)))) {
- primes.push_back(i);
- }
- }
- }
- bool is_prime(int n) {
- if (n < 2) return false;
- if (n == 2) return true;
- if (n % 2 == 0) return false;
- if (!(isVisited[n / 64] & (1LL << (n % 64)))) return true;
- return false;
- }
- int pf_count(int n) {
- int cnt = 0;
- for (int p : primes) {
- if (p * p > n) break;
- if (n % p == 0) {
- ++cnt;
- while (n % p == 0) n /= p;
- }
- }
- if (n > 1) ++cnt;
- return cnt;
- }
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace __gnu_pbds;
- typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
- int main() {
- //~ Sieve_of_Eratosthenes();
- //~ int n = 10;
- //bool f = is_prime(n);//returns true if n is prime and returns false if n is not a prime number
- //cout << pf_count(n) << '\n'; //how many primes present in prime factorization of n
- //os.order_of_key(n) => returns counts of elements less then n
- //os.find_by_order(n) => nth position value
- //~ ordered_set os;
- //~ os.insert(10);
- //~ os.insert(20);
- //~ os.insert(30);
- //~ cout << os.order_of_key(30) << '\n';
- //~ cout << *os.find_by_order(2) << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement