poj2407 Relatives 欧拉函数基本应用
来源:互联网 发布:油蜡皮沙发价格知乎 编辑:程序博客网 时间:2024/03/29 05:30
题意很简单 就是欧拉函数的定义:
欧拉函数是指:对于一个正整数n,小于n且和n互质的正整数(包括1)的个数,记作φ(n) 。题目求的就是φ(n)
根据 通式:φ(x)=x*(1-1/p1)*(1-1/p2)*(1-1/p3)*(1-1/p4)…..(1-1/pn),其中p1, p2……pn为x的所有质因数,x是不为0的整数
然后利用以下性质变形:
欧拉函数是积性函数——若m,n互质,φ(mn)=φ(m)φ(n)。
若n是质数p的k次幂,φ(n)=p^k-p^(k-1)=(p-1)p^(k-1),因为除了p的倍数外,其他数都跟n互质。
最后 就是 先把 题目给的 n 进行素因子分解 n=pi^mi*......*pj^mj,求φ(n)其实按照积极函数性质一 φ(n)=φ(pi^mi*)*.....*φ(pj^mj),然后分别求出 φ(pi^mi*) 根据积极函数的性质二 φ(pi^mi) =(pi-1)*pi^(mi-1)
#include<iostream>#include<cstdio>#include<list>#include<algorithm>#include<cstring>#include<string>#include<queue>#include<stack>#include<map>#include<vector>#include<cmath>#include<memory.h>#include<set>#define ll long long#define LL __int64#define eps 1e-8//const ll INF=9999999999999;#define inf 0xfffffffusing namespace std;//vector<pair<int,int> > G;//typedef pair<int,int> P;//vector<pair<int,int>> ::iterator iter;////map<ll,int>mp;//map<ll,int>::iterator p;////vector<int>G[30012];LL p[100012],m[100012];int main(void){LL n;while(cin>>n,n){LL temp=n;LL cntp=0;for(ll i=2;i*i<=temp;){if(n%i==0){p[cntp]=i;LL cntm=0;while(n%i==0){n/=i;cntm++;}m[cntp++]=cntm;}else i++;}if(n>1){p[cntp]=n;m[cntp++]=1;}LL ans=1;for(LL i=0;i<cntp;i++)ans*=LL(double(p[i]-1)*pow(double(p[i]),double(m[i]-1)));cout<<ans<<endl;}}
- poj2407 Relatives 欧拉函数基本应用
- POJ2407:Relatives(欧拉函数)
- POJ2407 Relatives(欧拉函数)
- 欧拉函数 模板题 POJ2407 Relatives
- POJ2407 Relatives 【欧拉函数模板】
- 【欧拉函数】 poj2407 Relatives(裸欧拉函数)
- POJ2407---Relatives(求单个数的欧拉函数)
- POJ2407-Relatives(欧拉函数裸题)
- poj2407 欧拉函数
- POJ2407 欧拉函数
- Relatives(poj2407)(求大数的欧拉函数模板题)
- 欧拉函数的应用&&Relatives
- Relatives 【欧拉函数】
- Relatives---欧拉函数
- poj2407欧拉函数模板
- Relatives+水题+欧拉函数+素数打表的基本应用+poj
- POJ 2407 Relatives(欧拉函数的应用)
- 1874: Relatives欧拉函数
- LeetCode 之 Search for a Range
- mongodb集成spring
- mongodb分布式集群架构
- python 获取当前脚本所在路径
- VC++操作word
- poj2407 Relatives 欧拉函数基本应用
- Remove Nth Node From End of List
- Polygon获取中心点坐标
- 【C++】容器list的用法
- 3D圆环的射线拾取算法
- SpringMVC+Mybatis 基于maven archetype 模板项目搭建
- JasperReport学习时的demo
- 大话数据结构--串string
- DirectX 绘制