Algorithm: Euler function
欧拉函数。
phi(n)表示比n小的与n互质的数的个数,比如
phi(1) = 1;
phi(2) = 1;
phi(3) = 2;
phi(4) = 2;
phi(5) = 4;
性质:
1. 如果p为质数,则phi(p) = p-1;
2. 如果p为质数并且a为正整数,则phi(p^a) = p^a - p^(a-1);
证明:p为质数,所以所有可以和p相乘小于p^a的数有p^a/p = p^(a-1)个,剩下的都与p^a互质。
3. phi(ab) = phi(a)*phi(b)
4. n = p1^a1*p2^a2*...*pk^ak
phi(n) = phi(p1^a1)*phi(p2^a2)*...*phi(pk^ak)
= (p1^a1-p1^(a1-1))*(p2^a2-p2^(a2-1))*...(pk^ak-pk^(ak-1))
=n*(1-1/p1)*(1-1/p2)*...*(1-1/pk)
实现代码:
int phi (int n) {
int result = n;
for (int i=; i*i<=n; ++i)
if (n % i == ) {
while (n % i == )
n /= i;
result -= result / i;
}
if (n > )
result -= result / n;
return result;
}
应用:
欧拉定理:a^(phi(m)) = 1 (mod m)
其中a与m互质
费马定理:a^(m-1) = 1 (mod m)
其中a与m互质
Algorithm: Euler function的更多相关文章
- hdu 2824 The Euler function
The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu 2824 The Euler function 欧拉函数打表
The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDU 6322.Problem D. Euler Function -欧拉函数水题(假的数论题 ̄▽ ̄) (2018 Multi-University Training Contest 3 1004)
6322.Problem D. Euler Function 题意就是找欧拉函数为合数的第n个数是什么. 欧拉函数从1到50打个表,发现规律,然后勇敢的水一下就过了. 官方题解: 代码: //1004 ...
- HDU2824 The Euler function
Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Description The Eule ...
- HDU——2824 The Euler function
The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDU——T 2824 The Euler function
http://acm.hdu.edu.cn/showproblem.php?pid=2824 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- The Euler function[HDU2824]
The Euler functionTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- The Euler function(欧拉函数)
The Euler function Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) ...
- hdu 2824 The Euler function(欧拉函数)
题目链接:hdu 2824 The Euler function 题意: 让你求一段区间的欧拉函数值. 题解: 直接上板子. 推导过程: 定义:对于正整数n,φ(n)是小于或等于n的正整数中,与n互质 ...
随机推荐
- ABP开发框架前后端开发系列---(2)框架的初步介绍
在前面随笔<ABP开发框架前后端开发系列---(1)框架的总体介绍>大概介绍了这个ABP框架的主要特点,以及介绍了我对这框架的Web API应用优先的一些看法,本篇继续探讨ABP框架的初步 ...
- Xamarin.Forms特殊的视图BoxView
Xamarin.Forms特殊的视图BoxView BoxView是Xamarin.Forms比较特殊的视图.该视图构建非常简单,其作用也很单一.它的作用就是构成一个特定颜色的色块.在界面设计中, ...
- luogu P3402 最长公共子序列
题目背景 DJL为了避免成为一只咸鱼,来找Johann学习怎么求最长公共子序列. 题目描述 经过长时间的摸索和练习,DJL终于学会了怎么求LCS.Johann感觉DJL孺子可教,就给他布置了一个课后作 ...
- ssm框架 spring的主配置文件 spring-mvc主配置文件 web.xml配置文件(基础的配置文件)
1.spring主配置文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=" ...
- 编译lua
http://www.lua.org/ 新建一个 static library 工程,把解压得到的目录下的src子目录中的所有.h和.c文件拷贝到新工程目录下. 工程中删除自动生成的 main.c 文 ...
- dprobe and dprofile
https://github.com/xwlan dprofiler Lightweight CPU Memory I/O and Lock profiler for Windows dprobe D ...
- SQL-基础学习3--通配符:LIKE,%,(_); 拼接:+,||,concat;
第六课 用通配符进行过滤 6.1 LIKE操作符 通配符本身实际上是SQL的WHERE子句中有特殊含义的字符,SQL支持几种通配符.为在搜索子句中使用通配符,必须使用LIKE操作符.LIKE指示DB ...
- vcl.Forms等与VCL界面有关的单元不支持跨平台
vcl.Forms等与VCL界面有关的单元不支持跨平台 midaslib也不支持
- [NSURL URLWithString:] 返回nil
具体问题原因是url中输入的有中文,那么这个就看作非法的字符无法识别.这种的必须使用post方式来发送消息.具体为: tmp = mainurl; [parameters app ...
- mac安装.net core
https://www.microsoft.com/net/core#macos Install for macOS 10.11 or higher (64 bit) 1 Install pre-re ...