Topic Links:
http://acm.nefu.edu.cn/JudgeOnline/problemshow.php?problem_id=120
Main topic:
Give a number p, if MP = 2^p-1 is a mason prime, then output "yes", otherwise output "no".
Ideas:
This problem p is less than 62. MP is less than 2^62-1. If the direct number of primes will be relatively slow, using the Sieve method of the amount of data
It's going to be big. So here is the rule of lucas-lehmer judgment.
Lucas-lehmer decision rule Specific steps:
If you want to determine the integer MP = 2^p-1, make lucas sequence date[1] = 4,l (i) = (L (i-1) ^2-2)% MP,
If date[p-1] = = 0, then the number of MP is Mason Prime. In particular, the first Mason prime number 2 is to be specially sentenced.
AC Code:
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring>using namespace Std;long Long Date[70];long long Multi (Long long A,long long B,long long m)//a * B% m{long long ret = 0; while (b) {if (b & 1) ret = (ret + a)% m; b >>= 1; A = (a << 1)% m; } return ret;} int main () {Long long sum,temp; int t,n; scanf ("%d", &t); while (t--) {scanf ("%d", &n); sum = 1; sum = (sum<<n); Sum-= 1; DATE[1] = 4; for (int i = 2; I <= N-1; ++i) {temp = Multi (date[i-1],date[i-1],sum); Date[i] = (temp-2)% sum; } if (N = = 2) printf ("yes\n"); else {if (date[n-1] = = 0) printf ("yes\n"); else printf ("no\n"); }} return 0;}
NEFU120 Mason Prime number "Lucas-lehmer judgment"