Skip to content

Commit 446bd96

Browse files
small updates
1 parent a942d27 commit 446bd96

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

Cpp/library/generators.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33

44
namespace GEN {
55

6+
template <typename T>
7+
T rand(T low, T high) {
8+
std::uniform_int_distribution<T> uni(low, high);
9+
return uni(rng);
10+
}
11+
612
template <typename T>
713
vector<vector<T>> subarrays(vector<T>& arr) {
814
int n = arr.size();

Cpp/library/number/Sieve.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,28 @@ struct Sieve {
5656
return ans;
5757
}
5858

59+
long long countDivisors(long long n) {
60+
if (n == 1) return 1;
61+
long long ans = 1;
62+
for (int i = 0;; i++) {
63+
if (primes[i] * primes[i] * primes[i] > n) break;
64+
int cnt = 1;
65+
while (n % primes[i] == 0) {
66+
n /= primes[i];
67+
cnt++;
68+
}
69+
ans *= cnt;
70+
}
71+
72+
if (isPrime[n])
73+
ans = ans * 2;
74+
else if (isPrime[sqrt(n)] && (long long) sqrt(n) == sqrt(n))
75+
ans = ans * 3;
76+
else if (n != 1)
77+
ans = ans * 4;
78+
return ans;
79+
}
80+
5981
vector<pll> divisorPair(long long x) {
6082
vector<pll> res;
6183
for (long long i = 1; i * i <= x; i++) {

Cpp/output/test.sh

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ for ((i = 1; ; ++i)); do
66
# ./a < int > out1
77
# ./brute < int > out2
88
# diff -w out1 out2 || break
9-
diff -w <(./a <int) <(./brute <int) || break
9+
diff -w <(./main <int) <(./brute <int) || break
1010
done

0 commit comments

Comments
 (0)