威尔逊定理

威尔逊定理:

\[(p-1)!\equiv -1\pmod{p} \]

证明:

我们只道在模奇素数 \(p\) 意义下,\(1,2,\dots,p-1\) 都存在逆元且唯一,且逆元也一定在 \(1\le a' \le p-1\),那么只需要将一个数与其逆元配对发现其乘积均为(同余意义下)\(1\),但前提是这个数的逆元不等于自身。那么很显然 \((p-1)!\bmod p\) 就是逆元等于其自身的数的乘积,这两个数为 \(\pm 1\)。在 \(p\)\(2\) 时单独讨论即可。

其实通俗感性的理解就是:1~p-1,每个a与其逆元配对相消,最后只留下1和p-1,p-1%p=-1,1*-1=-1.

参考:OIWIKI,Alex_wei的博客

做题做题!!

UVA1434 YAPTCHA

The math department has been having problems lately. Due to immense amount of unsolicited auto-mated programs which were crawling across their pages, they decided to put Yet-Another-PublicTuring-Test-to-Tell-Computers-and-Humans-Apart on their webpages. In short, to get access to their scientific papers, one have to prove yourself eligible and worthy, i.e. solve a mathematic riddle.
However, the test turned out difficult for some math PhD students and even for some professors. Therefore, the math department wants to write a helper program which solves this task (it is not irrational, as they are going to make money on selling the program).
The task that is presented to anyone visiting the start page of the math department is as follows:
given a natural \(n\), compute

\[S_n=\sum\limits_{k=1}^n\left\lfloor{\dfrac{(3k+6)!+1}{3k+7}-\left\lfloor\dfrac{(3k+6)!}{3k+7}\right\rfloor}\right\rfloor \]

原题:https://onlinejudge.org/external/14/p1434.pdf

分析:

分类讨论,看 \(3k+7\) 是否为质数

1.是质数,则

\((3k+6)! \equiv -1\pmod{3k+7}\)

\((3k+6)!+1=k(3k+7)\)

\(\left\lfloor{\dfrac{(3k+6)!+1}{3k+7}-\left\lfloor\dfrac{(3k+6)!}{3k+7}\right\rfloor}\right\rfloor = \left\lfloor{k-\left\lfloor k -\dfrac{1}{3k+7}\right\rfloor}\right\rfloor =1\)

  1. 不是质数,则有 \((3k+7)\mid (3k+6)!\)

\((3k+6)! \equiv 0\pmod{3k+7}\)

\((3k+6)!=k(3k+7)\)

\(\left\lfloor{\dfrac{(3k+6)!+1}{3k+7}-\left\lfloor\dfrac{(3k+6)!}{3k+7}\right\rfloor}\right\rfloor = \left\lfloor{k+\dfrac{1}{3k+7} - k}\right\rfloor =0\)

所以,每一项值,只与 \(3k+7\) 是否为质数有关。

得出

\(\sum\limits_{k=1}^n\left\lfloor{\dfrac{(3k+6)!+1}{3k+7}-\left\lfloor\dfrac{(3k+6)!}{3k+7}\right\rfloor}\right\rfloor=\sum\limits_{k=1}^n[3k+7 \text{ is prime}]\)

代码很轻松就可以写出来:

#include <bits/stdc++.h>
#define rei register int
#define LL long long
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define cvar int n, m, T;
#define rep(i, s, n, c) for (register int i = s; i <= n; i+=c)
#define repd(i, s, n, c) for (register int i = s; i >= n; i-=c)
#define CHECK cout<<"WALKED"<<endl;
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0' && ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();return x*f;}
#define pb push_back
#define ls id<<1
#define rs id<<1|1
const int INF = INT_MAX;
long long binpow(long long a, long long b, LL mod){long long res = 1;  while (b > 0){if (b & 1) res = res * a % mod;a = a * a % mod;  b >>= 1;  }  return res;}
using namespace std;
bitset<4000015>flag;
LL sum[4000015];
const int maxn = 3000010;
void init()
{
	rep (i, 2, maxn - 1, 1)
		if (1ll * i * i <= maxn)
		rep (j, i * i, maxn, i)
			flag[j] = true;
	rep (k, 1, 1000000, 1)
		sum[k] = sum[k - 1] + !flag[3 * k + 7];
}
int main()
{
	init();
	int T, n;
	cin >> T;
	while (T--)
	{
		n = read();
		cout << sum[n] << endl;
	}
	return 0;
}
posted @ 2022-10-22 21:48  Vegdie  阅读(70)  评论(0编辑  收藏  举报