-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
111 changed files
with
7,740 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-Wall -Wextra -pedantic -std=c++11 -Wshadow -Wformat=2 -Wfloat-equal -Wconversion -Wlogical-op -Wshift-overflow=2 -Wduplicated-cond -Wcast-qual -Wcast-align -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-Wl,--stack,268435456 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
|
||
typedef struct { | ||
unsigned long long number; | ||
unsigned long long divisors; | ||
} small_max; | ||
|
||
static const unsigned long long primes[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47 }; | ||
static const unsigned long long primorials[] = | ||
{ 2, 6, 30, 210, 2310, 30030, 510510, 9699690, 223092870, 6469693230, | ||
200560490130, 7420738134810, 304250263527210, 13082761331670030, | ||
614889782588491410 }; | ||
|
||
static const unsigned num_primes = sizeof primorials / sizeof primorials[0]; | ||
|
||
small_max max_divisors(unsigned long long limit); | ||
small_max best_with(unsigned long long limit, unsigned index, unsigned multiplicity); | ||
void factor(unsigned long long number); | ||
|
||
int main(int argc, char *argv[]) { | ||
unsigned long long limit; | ||
limit = argc > 1 ? strtoull(argv[1],NULL,0) : 1000000; | ||
small_max best = max_divisors(limit); | ||
printf("\nSmallest number not exceeding %llu with most divisors:\n",limit); | ||
printf("%llu with %llu divisors\n", best.number, best.divisors); | ||
factor(best.number); | ||
return 0; | ||
} | ||
|
||
small_max max_divisors(unsigned long long limit) { | ||
small_max result; | ||
if (limit < 3) { | ||
result.number = limit; | ||
result.divisors = limit; | ||
return result; | ||
} | ||
unsigned idx = num_primes; | ||
small_max best = best_with(limit,0,1); | ||
printf("Largest power of 2: %llu = 2^%llu\n", best.number, best.divisors-1); | ||
for(idx = 1; idx < num_primes && primorials[idx] <= limit; ++idx) { | ||
printf("Using primes to %llu:\n", primes[idx]); | ||
unsigned long long test = limit, remaining = limit; | ||
unsigned multiplicity = 0; | ||
do { | ||
++multiplicity; | ||
test /= primorials[idx]; | ||
remaining /= primes[idx]; | ||
result = best_with(remaining, idx-1, multiplicity); | ||
for(unsigned i = 0; i < multiplicity; ++i) { | ||
result.number *= primes[idx]; | ||
} | ||
result.divisors *= multiplicity + 1; | ||
if (result.divisors > best.divisors) { | ||
printf("New largest divisor count: %llu for\n ", result.divisors); | ||
factor(result.number); | ||
best = result; | ||
} else if (result.divisors == best.divisors && result.number < best.number) { | ||
printf("Smaller number with %llu divisors:\n ", result.divisors); | ||
factor(result.number); | ||
best = result; | ||
} | ||
}while(test >= primorials[idx]); | ||
} | ||
return best; | ||
} | ||
|
||
small_max best_with(unsigned long long limit, unsigned index, unsigned multiplicity) { | ||
small_max result = {1, 1}; | ||
if (index == 0) { | ||
while(limit > 1) { | ||
result.number *= 2; | ||
++result.divisors; | ||
limit /= 2; | ||
} | ||
return result; | ||
} | ||
small_max best = {0,0}; | ||
unsigned long long test = limit, remaining = limit; | ||
--multiplicity; | ||
for(unsigned i = 0; i < multiplicity; ++i) { | ||
test /= primorials[index]; | ||
remaining /= primes[index]; | ||
} | ||
do { | ||
++multiplicity; | ||
test /= primorials[index]; | ||
remaining /= primes[index]; | ||
result = best_with(remaining, index-1, multiplicity); | ||
for(unsigned i = 0; i < multiplicity; ++i) { | ||
result.number *= primes[index]; | ||
} | ||
result.divisors *= multiplicity + 1; | ||
if (result.divisors > best.divisors) { | ||
best = result; | ||
} else if (result.divisors == best.divisors && result.number < best.number) { | ||
best = result; | ||
} | ||
}while(test >= primorials[index]); | ||
return best; | ||
} | ||
|
||
void factor(unsigned long long number) { | ||
unsigned long long num = number; | ||
unsigned idx, mult; | ||
printf("%llu =", number); | ||
for(idx = 0; num > 1 && idx < num_primes; ++idx) { | ||
mult = 0; | ||
while(num % primes[idx] == 0) { | ||
num /= primes[idx]; | ||
++mult; | ||
} | ||
printf("%s %llu ^ %u", idx ? " *" : "", primes[idx], mult); | ||
} | ||
printf("\n"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include <bits/stdc++.h> | ||
#define fi first | ||
#define se second | ||
#define pb push_back | ||
#define all(x) (x).begin(), (x).end() | ||
using namespace std; | ||
typedef long long ll; | ||
typedef pair<int, int> ii; | ||
|
||
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); | ||
|
||
ll randInt(const ll &l, const ll &r) { return rng() % (r - l + 1) + l; } | ||
|
||
void weakTree(int N) { | ||
vector<int>p(N + 1, 0), idx(N + 1); | ||
iota(all(idx), 0); | ||
shuffle(idx.begin() + 1, idx.end(), rng); | ||
for(int i = 2; i <= N; i++) | ||
p[i] = randInt(1, i - 1); | ||
for(int i = 1; i <= N; i++) { | ||
int par = idx[p[i]], u = idx[i]; | ||
if(par) | ||
cout << par << ' ' << u << '\n'; | ||
} | ||
} | ||
|
||
void line(int N) { | ||
vector<int> idx(N + 1); | ||
iota(all(idx), 0); | ||
shuffle(idx.begin() + 1, idx.end(), rng); | ||
for(int i = 1; i < N; i++) | ||
cout << idx[i] << ' ' << idx[i + 1] << '\n'; | ||
} | ||
|
||
void sun(int N) { | ||
int root = randInt(1, N); | ||
for(int i = 1; i < N; i++) | ||
if(i != root) | ||
cout << i << ' ' << root << '\n'; | ||
} | ||
|
||
void randGraph(int N, int M) { // no self-loops / multiple edges. | ||
set<ii> edges; | ||
for(int i = 1; i <= M; i++) { | ||
int u = randInt(1, N), v = randInt(1, N); | ||
while(u == v || edges.count({u, v}) || edges.count({v, u})) | ||
u = randInt(1, N), v = randInt(1, N); | ||
edges.insert({u, v}); | ||
cout << u << ' ' << v << '\n'; | ||
} | ||
} | ||
|
||
signed main() { | ||
randGraph(10, 35); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <bits/stdc++.h> | ||
#include "treegenerator.h" | ||
#define int long long | ||
#define fi first | ||
#define se second | ||
#define pb push_back | ||
using namespace tree_generator_by_ouuan; | ||
using namespace std; | ||
|
||
signed main() | ||
{ | ||
freopen("test.inp", "w", stdout); | ||
int n; std::cin >> n; | ||
Tree t(n); | ||
cout << n << '\n' << t; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"cmd": ["g++.exe", "-std=c++11", "-Wall", "-Wextra", "-Wshadow" "${file}", "-o", "${file_base_name}.exe", "&&" , "${file_base_name}.exe<input.txt>output.txt"], | ||
"shell":true, | ||
"working_dir":"$file_path", | ||
"selector":"source.cpp" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"shell_cmd": "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\"", | ||
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", | ||
"working_dir": "${file_path}", | ||
"selector": "source.c++, source.cpp, source.cc, source.cxx", | ||
|
||
"variants": | ||
[ | ||
{ | ||
"name": "Run in Terminal", | ||
|
||
"windows":{ | ||
"shell_cmd": "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && start cmd /k $file_base_name ", | ||
// "shell_cmd": "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && start \"$file_base_name\" call $file_base_name" | ||
}, | ||
|
||
"shell": true, | ||
}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <bits/stdc++.h> | ||
#define fi first | ||
#define se second | ||
#define pb push_back | ||
#define all(x) (x).begin(), (x).end() | ||
using namespace std; | ||
typedef long long ll; | ||
typedef pair<int, int> ii; | ||
|
||
signed main() { | ||
|
||
} |
Oops, something went wrong.