Skip to content

Commit

Permalink
small updates
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhdeepsingh committed Oct 10, 2020
1 parent a942d27 commit 446bd96
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Cpp/library/generators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

namespace GEN {

template <typename T>
T rand(T low, T high) {
std::uniform_int_distribution<T> uni(low, high);
return uni(rng);
}

template <typename T>
vector<vector<T>> subarrays(vector<T>& arr) {
int n = arr.size();
Expand Down
22 changes: 22 additions & 0 deletions Cpp/library/number/Sieve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,28 @@ struct Sieve {
return ans;
}

long long countDivisors(long long n) {
if (n == 1) return 1;
long long ans = 1;
for (int i = 0;; i++) {
if (primes[i] * primes[i] * primes[i] > n) break;
int cnt = 1;
while (n % primes[i] == 0) {
n /= primes[i];
cnt++;
}
ans *= cnt;
}

if (isPrime[n])
ans = ans * 2;
else if (isPrime[sqrt(n)] && (long long) sqrt(n) == sqrt(n))
ans = ans * 3;
else if (n != 1)
ans = ans * 4;
return ans;
}

vector<pll> divisorPair(long long x) {
vector<pll> res;
for (long long i = 1; i * i <= x; i++) {
Expand Down
2 changes: 1 addition & 1 deletion Cpp/output/test.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ for ((i = 1; ; ++i)); do
# ./a < int > out1
# ./brute < int > out2
# diff -w out1 out2 || break
diff -w <(./a <int) <(./brute <int) || break
diff -w <(./main <int) <(./brute <int) || break
done

0 comments on commit 446bd96

Please sign in to comment.