首页 > 其他分享 >威尔逊定理

威尔逊定理

时间:2022-10-22 21:55:57浏览次数:80  
标签:lfloor right dfrac 定理 威尔逊 rfloor 3k left

威尔逊定理:

\[(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;
}

标签:lfloor,right,dfrac,定理,威尔逊,rfloor,3k,left
From: https://www.cnblogs.com/CYLSY/p/16817416.html

相关文章

  • 容斥定理
    用来求解集合计数问题,求解多个集合并的数目,转化为求交,结果等于加上奇数集合交的数目,将去偶数集合交的数目经典题目求错位排列,反求不是错位排列的条件,在交集合的时候可以合......
  • 主定理
    主定理:将一个规模为n的问题,分治成a个\(\lceil\dfrac{n}{b}\rceil\)的子问题,每次带来的额外计算为\(\mathcal{O}(n^d)\),可得到以下关系式:\[T(n)=aT(\lceil\dfrac{n......
  • [安乐椅#3] 蝴蝶定理
    已知:抛物线\(C:y^2=2px(p>0)\),\(D(n,0),E(m,0)\)为其对称轴上两点,\(M\)是\(C\)上异于原点\(O\)的一动点,直线\(ME\)交\(C\)于\(N\),直线\(MD\)交\(C\)于\(......
  • 【高等数学基础进阶】微分中值定理及导数应用
    一、微分中值定理定理1(费马引理):如果函数$f(x)$在$x_{0}$处可导,且在$x_{0}$处取得极值,那么$f'(x_{0})=0$ 定理2(罗尔定理):若$f(x)$在$[a,b]$上连续$f(x)$在$(a,b)$......
  • 【笔记】裴蜀定理
    裴蜀定理:\[\foralla,b\in\mathbb{Z},\existsx,y\in\mathbb{Z},ax+by=\gcd(a,b)\]要求\(x,y\)不同时为\(0\)。推论:\[\begin{gathered}\text{对于}a,b\in......
  • 【模板】中国剩余定理
    中国剩余定理:同余方程组:\[x\equiva_i\pmod{m_i}\,(i\in\left[1,n\right])\](其中\(\foralli,j\in\left[1,n\right],\gcd(m_i,m_j)=1\))有解,且这些解构成一个......
  • CF1713F Lost Array(FWT,卢卡斯定理,*)
    CF1713FLostArray矩阵\(b[0\toN][0\toN]\)。\(b[i][0]=0\),\(b[0][i](i>1)=a[i]\)。\(b[i][j]=b[i-1][j]\oplusb[i][j-1]\)。给出\(c[1\toN]=b[......
  • 费用流消圈定理
    有负权环的费用流直接跑EK会死循环,根据消圈定理:该最小费用流最后的残余网络不存在负权环。可以提前消去负权环,boolclear_circle(int&cost){memset(cnt,0,sizeof......
  • 磁介质中的安培环路定理
    由真空中的安培环路定理\(\int\vec{B_0}d\vec{l}=\mu_0\sumI_c①\)在磁介质中,由于磁介质中的电子会受到电流的影响产生感应电流,设其为\(I_s\),根据在真空中的环路......
  • lucas定理快速求解组合数(适用于MOD较小)
    lucus求解组合数的时间复杂度为O(MODlogn(MOD))适用于MOD较小但n较大的情况模板:LLMOD=1e6+3;LLQuickExp(LLbase,LLexp){LLres=1;while(exp){......