欧拉目录
- 欧拉
- 威尔逊定理
- 当为素数是: (n−1)!≡−1(modn) 或者是 (n−2)!≡1(modn)
- A - Zball in Tina Town
- B - YAPTCHA
欧拉
欧拉函数
- 定义:
ϕ(i)表示第i个欧拉函数的值,代表了从1到i与i互质的数的个数,例如ϕ(8)=4 因为1,3,5,7均和8互质 - 通式 :
- 一些性质
1,如果x是质数则 ϕ(x)=x-1;
2,如果a是质数不是n的因子则 ϕ(an)=ϕ(n)(a-1);进一步推如果n是奇数则ϕ(2n)=ϕ(n);
3,如果a是n的质因子则 ϕ(an)=ϕ(n)a;
4,如果n和m互质 则 ϕ(nm)= ϕ(n)*ϕ(m);
5,如果n>2则 ϕ(n)一定是偶数
6,如果p是质数 则 ϕ(pq)=pq-pq-1;
写一下欧拉函数 时间复杂度是O(根n);
写一个大数的欧拉函数,其实就是利用欧拉筛法,时间复杂度O(N)
—————————————————————————————————————————————————————
欧拉定理:
就是欧拉函数的一个分支,
- aϕ(m)=1(modm)(a,m互质);
—————————————————————————————————————————————————————
欧拉降幂
- 在大数取余中常用
- 原理很简单,就是 at%m;其中t=k*ϕ(m)+r;
所以式子可以化成aϕ(m)*k*ar%m;
由欧拉函数得 aϕ(m)%m==1;
所以aϕ(m)*kar%m=1ar%m;
这就简化了很多不必要的计算; - 所以我们可以推出
- 欧拉降幂在a与m互质情况下的公式:
aq=aq%ϕ(m)(mod m); - 当然还有通用公式(不管是否互质):
当q大于ϕ(m)时: aq=aq%ϕ(m)+ϕ(m)(mod m);
可以去做做 洛谷上的板子题P5091
威尔逊定理
其实威尔逊定理也就是一个式子,很简单的。
当为素数是: (n−1)!≡−1(modn) 或者是 (n−2)!≡1(modn)
剩下的也不多说哦,加上连个例题吧;
(1)HDU5391
A - Zball in Tina Town
Tina Town is a friendly place. People there care about each other.
Tina has a ball called zball. Zball is magic. It grows larger every day. On the first day, it becomes 1 time as large as its original size. On the second day,it will become 2 times as large as the size on the first day. On the n-th day,it will become n times as large as the size on the (n-1)-th day. Tina want to know its size on the (n-1)-th day modulo n.
- Input
The first line of input contains an integer T, representing the number of cases.
The following T lines, each line contains an integer n, according to the description.
T≤105,2≤n≤109 - Output
For each test case, output an integer representing the answer. - Sample Input
2
3
10 - Sample Output
2
0 - 思路分析 就是个简单的运用威尔逊定理
(2)HDU2973
B - YAPTCHA
- The math department has been having problems lately. Due to immense amount of unsolicited automated programs which were crawling across their pages, they decided to put Yet-Another-Public-Turing-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
where [x] denotes the largest integer not greater than x.
- Input
The first line contains the number of queries t (t <= 106). Each query consist of one natural number n (1 <= n <= 106). - Output
For each n given in the input output the value of Sn. - Sample Input
13
1
2
3
4
5
6
7
8
9
10
100
1000
10000 - Sample Output
0
1
1
2
2
2
2
3
3
4
28
207
1609 - 思路分析 上个题是直接判断n 这个是判断3*n+7其实也一样,只不过这个用到了前缀和,而且这个题会卡你内存就是bool和int这样子的
具体解释可以参照orz的博客 代码