forked from yosupo06/library-checker-problems
-
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.
Merge pull request yosupo06#1168 from maspypy/999
テストケース追加(issue 999)
- Loading branch information
Showing
10 changed files
with
261 additions
and
70 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 |
---|---|---|
@@ -1,22 +1,22 @@ | ||
#include <cstdlib> | ||
#include <cstdio> | ||
#include "random.h" | ||
#include <iostream> | ||
|
||
using namespace std; | ||
using ll = long long; | ||
|
||
int main(int, char* argv[]) { | ||
long long seed = atoll(argv[1]); | ||
auto gen = Random(seed); | ||
|
||
long long seed = atoll(argv[1]); | ||
auto gen = Random(seed); | ||
|
||
int t = 100; | ||
printf("%d\n", t); | ||
for (int i = 0; i < t; i++) { | ||
int x, y, m; | ||
m = gen.uniform(800'000'000 / 2, 1'000'000'000 / 2) * 2; | ||
x = gen.uniform(0, m - 1); | ||
y = gen.uniform(0, m - 1); | ||
printf("%d %d %d\n", x, y, m); | ||
} | ||
return 0; | ||
int t = 100; | ||
printf("%d\n", t); | ||
for (int i = 0; i < t; i++) { | ||
int x, y, m; | ||
m = gen.uniform(800'000'000 / 2, 1'000'000'000 / 2) * 2; | ||
x = gen.uniform(0, m - 1); | ||
y = gen.uniform(0, m - 1); | ||
printf("%d %d %d\n", x, y, m); | ||
} | ||
return 0; | ||
} |
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 |
---|---|---|
@@ -1,22 +1,22 @@ | ||
#include <cstdlib> | ||
#include <cstdio> | ||
#include "random.h" | ||
#include <iostream> | ||
|
||
using namespace std; | ||
using ll = long long; | ||
|
||
int main(int, char* argv[]) { | ||
long long seed = atoll(argv[1]); | ||
auto gen = Random(seed); | ||
|
||
long long seed = atoll(argv[1]); | ||
auto gen = Random(seed); | ||
|
||
int t = 100; | ||
printf("%d\n", t); | ||
for (int i = 0; i < t; i++) { | ||
int x, y, m; | ||
m = gen.uniform(800'000'000 / 2, 1'000'000'000 / 2) * 2; | ||
x = gen.uniform(0, m / 2 - 1) * 2; | ||
y = gen.uniform(0, m / 2 - 1) * 2 + 1; | ||
printf("%d %d %d\n", x, y, m); | ||
} | ||
return 0; | ||
int t = 100; | ||
printf("%d\n", t); | ||
for (int i = 0; i < t; i++) { | ||
int x, y, m; | ||
m = gen.uniform(800'000'000 / 2, 1'000'000'000 / 2) * 2; | ||
x = gen.uniform(0, m / 2 - 1) * 2; | ||
y = gen.uniform(0, m / 2 - 1) * 2 + 1; | ||
printf("%d %d %d\n", x, y, m); | ||
} | ||
return 0; | ||
} |
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 |
---|---|---|
@@ -1,22 +1,22 @@ | ||
#include <cstdlib> | ||
#include <cstdio> | ||
#include "random.h" | ||
#include <iostream> | ||
|
||
using namespace std; | ||
using ll = long long; | ||
|
||
int main(int, char* argv[]) { | ||
long long seed = atoll(argv[1]); | ||
auto gen = Random(seed); | ||
|
||
long long seed = atoll(argv[1]); | ||
auto gen = Random(seed); | ||
|
||
int t = 100; | ||
printf("%d\n", t); | ||
for (int i = 0; i < t; i++) { | ||
int x, y, m; | ||
m = gen.uniform(800'000'000, 1'000'000'000); | ||
x = gen.uniform(0, m - 1); | ||
y = gen.uniform(0, m - 1); | ||
printf("%d %d %d\n", x, y, m); | ||
} | ||
return 0; | ||
int t = 100; | ||
printf("%d\n", t); | ||
for (int i = 0; i < t; i++) { | ||
int x, y, m; | ||
m = gen.uniform(800'000'000, 1'000'000'000); | ||
x = gen.uniform(0, m - 1); | ||
y = gen.uniform(0, m - 1); | ||
printf("%d %d %d\n", x, y, m); | ||
} | ||
return 0; | ||
} |
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,34 @@ | ||
#include <cstdlib> | ||
#include <cstdio> | ||
#include "random.h" | ||
|
||
using namespace std; | ||
using ll = long long; | ||
|
||
int mod_pow(ll a, ll n, int mod) { | ||
assert(0 <= a && a < mod && 0 <= n); | ||
ll r = 1; | ||
while (n) { | ||
if (n & 1) r = r * a % mod; | ||
a = a * a % mod, n >>= 1; | ||
} | ||
return r; | ||
} | ||
|
||
int main(int, char* argv[]) { | ||
long long seed = atoll(argv[1]); | ||
auto gen = Random(seed); | ||
|
||
int t = 100; | ||
printf("%d\n", t); | ||
for (int i = 0; i < t; i++) { | ||
int x, y, m; | ||
m = gen.uniform(800'000'000, 1'000'000'000); | ||
x = gen.uniform(0, m - 1); | ||
// y = gen.uniform(0, m - 1); | ||
int n = gen.uniform<int>(0, m); | ||
y = mod_pow(x, n, m); | ||
printf("%d %d %d\n", x, y, m); | ||
} | ||
return 0; | ||
} |
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,69 @@ | ||
#include <cstdlib> | ||
#include <cstdio> | ||
#include "random.h" | ||
|
||
using namespace std; | ||
using ll = long long; | ||
|
||
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); } | ||
|
||
int mod_pow(ll a, ll n, int mod) { | ||
assert(0 <= a && a < mod && 0 <= n); | ||
ll r = 1; | ||
while (n) { | ||
if (n & 1) r = r * a % mod; | ||
a = a * a % mod, n >>= 1; | ||
} | ||
return r; | ||
} | ||
|
||
bool primetest(int p) { | ||
if (p == 2 or p == 3 or p == 5 or p == 7) return true; | ||
if (p % 2 == 0 or p % 3 == 0 or p % 5 == 0 or p % 7 == 0) return false; | ||
if (p < 121) return p > 1; | ||
const int d = (p - 1) >> lowbit(p - 1); | ||
|
||
auto ok = [&](int a) -> bool { | ||
ll y = mod_pow(a, d, p); | ||
int t = d; | ||
while (y != 1 && y != p - 1 && t != p - 1) y = y * y % p, t <<= 1; | ||
if (y != p - 1 && t % 2 == 0) return false; | ||
return true; | ||
}; | ||
for (int a: {2, 7, 61}) | ||
if (!ok(a)) return false; | ||
return true; | ||
} | ||
|
||
int random_prime(Random& gen, int L, int R, bool safe) { | ||
if (!safe) { | ||
while (1) { | ||
int p = gen.uniform<int>(L, R); | ||
if (primetest(p)) return p; | ||
} | ||
} | ||
// L<=q=2p+1<=R | ||
while (1) { | ||
int p = random_prime(gen, L / 2, (R - 1) / 2, false); | ||
int q = 2 * p + 1; | ||
if (L <= q && q <= R && primetest(q)) return q; | ||
} | ||
} | ||
|
||
int main(int, char* argv[]) { | ||
long long seed = atoll(argv[1]); | ||
auto gen = Random(seed); | ||
|
||
int t = 100; | ||
printf("%d\n", t); | ||
for (int i = 0; i < t; i++) { | ||
int x, y, m; | ||
m = random_prime(gen, 800'000'000, 1'000'000'000, seed % 2); | ||
x = gen.uniform(0, m - 1); | ||
// y = gen.uniform(0, m - 1); | ||
int n = gen.uniform<int>(0, m); | ||
y = mod_pow(x, n, m); | ||
printf("%d %d %d\n", x, y, m); | ||
} | ||
return 0; | ||
} |
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 |
---|---|---|
@@ -1,22 +1,22 @@ | ||
#include <cstdlib> | ||
#include <cstdio> | ||
#include "random.h" | ||
#include <iostream> | ||
|
||
using namespace std; | ||
using ll = long long; | ||
|
||
int main(int, char* argv[]) { | ||
long long seed = atoll(argv[1]); | ||
auto gen = Random(seed); | ||
|
||
long long seed = atoll(argv[1]); | ||
auto gen = Random(seed); | ||
|
||
int t = gen.uniform(1, 100); | ||
printf("%d\n", t); | ||
for (int i = 0; i < t; i++) { | ||
int x, y, m; | ||
m = gen.uniform(1, 1'000'000'000); | ||
x = gen.uniform(0, m - 1); | ||
y = gen.uniform(0, m - 1); | ||
printf("%d %d %d\n", x, y, m); | ||
} | ||
return 0; | ||
int t = gen.uniform(1, 100); | ||
printf("%d\n", t); | ||
for (int i = 0; i < t; i++) { | ||
int x, y, m; | ||
m = gen.uniform(1, 1'000'000'000); | ||
x = gen.uniform(0, m - 1); | ||
y = gen.uniform(0, m - 1); | ||
printf("%d %d %d\n", x, y, m); | ||
} | ||
return 0; | ||
} |
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,67 @@ | ||
#include <cstdlib> | ||
#include <cstdio> | ||
#include "random.h" | ||
|
||
using namespace std; | ||
using ll = long long; | ||
|
||
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); } | ||
|
||
int mod_pow(ll a, ll n, int mod) { | ||
assert(0 <= a && a < mod && 0 <= n); | ||
ll r = 1; | ||
while (n) { | ||
if (n & 1) r = r * a % mod; | ||
a = a * a % mod, n >>= 1; | ||
} | ||
return r; | ||
} | ||
|
||
bool primetest(int p) { | ||
if (p == 2 or p == 3 or p == 5 or p == 7) return true; | ||
if (p % 2 == 0 or p % 3 == 0 or p % 5 == 0 or p % 7 == 0) return false; | ||
if (p < 121) return p > 1; | ||
const int d = (p - 1) >> lowbit(p - 1); | ||
|
||
auto ok = [&](int a) -> bool { | ||
ll y = mod_pow(a, d, p); | ||
int t = d; | ||
while (y != 1 && y != p - 1 && t != p - 1) y = y * y % p, t <<= 1; | ||
if (y != p - 1 && t % 2 == 0) return false; | ||
return true; | ||
}; | ||
for (int a: {2, 7, 61}) | ||
if (!ok(a)) return false; | ||
return true; | ||
} | ||
|
||
int random_prime(Random& gen, int L, int R, bool safe) { | ||
if (!safe) { | ||
while (1) { | ||
int p = gen.uniform<int>(L, R); | ||
if (primetest(p)) return p; | ||
} | ||
} | ||
// L<=q=2p+1<=R | ||
while (1) { | ||
int p = random_prime(gen, L / 2, (R - 1) / 2, false); | ||
int q = 2 * p + 1; | ||
if (L <= q && q <= R && primetest(q)) return q; | ||
} | ||
} | ||
|
||
int main(int, char* argv[]) { | ||
long long seed = atoll(argv[1]); | ||
auto gen = Random(seed); | ||
|
||
int t = 100; | ||
printf("%d\n", t); | ||
for (int i = 0; i < t; i++) { | ||
int x, y, m; | ||
m = random_prime(gen, 800'000'000, 1'000'000'000, seed % 2); | ||
x = gen.uniform(0, m - 1); | ||
y = gen.uniform(0, m - 1); | ||
printf("%d %d %d\n", x, y, m); | ||
} | ||
return 0; | ||
} |
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 |
---|---|---|
@@ -1,22 +1,22 @@ | ||
#include <cstdlib> | ||
#include <cstdio> | ||
#include "random.h" | ||
#include <iostream> | ||
|
||
using namespace std; | ||
using ll = long long; | ||
|
||
int main(int, char* argv[]) { | ||
long long seed = atoll(argv[1]); | ||
auto gen = Random(seed); | ||
|
||
long long seed = atoll(argv[1]); | ||
auto gen = Random(seed); | ||
|
||
int t = 100; | ||
printf("%d\n", t); | ||
for (int i = 0; i < t; i++) { | ||
int x, y, m; | ||
m = gen.uniform(1, 10); | ||
x = gen.uniform(0, m - 1); | ||
y = gen.uniform(0, m - 1); | ||
printf("%d %d %d\n", x, y, m); | ||
} | ||
return 0; | ||
int t = 100; | ||
printf("%d\n", t); | ||
for (int i = 0; i < t; i++) { | ||
int x, y, m; | ||
m = gen.uniform(1, 10); | ||
x = gen.uniform(0, m - 1); | ||
y = gen.uniform(0, m - 1); | ||
printf("%d %d %d\n", x, y, m); | ||
} | ||
return 0; | ||
} |
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
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