Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Primality tests: Add trivial code for seven-base#1562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Artoria2e5 wants to merge1 commit intocp-algorithms:main
base:main
Choose a base branch
Loading
fromArtoria2e5:primez
Open
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletionssrc/algebra/primality_tests.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -215,6 +215,31 @@ bool MillerRabin(u64 n) { // returns true if n is prime, else returns false.
It's also possible to do the check with only 7 bases: 2, 325, 9375, 28178, 450775, 9780504 and 1795265022.
However, since these numbers (except 2) are not prime, you need to check additionally if the number you are checking is equal to any prime divisor of those bases: 2, 3, 5, 13, 19, 73, 193, 407521, 299210837.

```cpp
bool MillerRabin(u64 n) { // returns true if n is prime, else returns false.
if (n < 2)
return false;

int r = 0;
u64 d = n - 1;
while ((d & 1) == 0) {
d >>= 1;
r++;
}

for (int a : {3, 5, 13, 19, 73, 193, 407521, 299210837}) {
if (n == a)
return true;
}

for (int a : {2, 325, 9375, 28178, 450775, 9780504, 1795265022}) {
if (check_composite(n, a, d, r))
return false;
}
return true;
}
```

## Practice Problems

- [SPOJ - Prime or Not](https://www.spoj.com/problems/PON/)
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp