poj2407 Relatives 欧拉函数基本应用

题意很简单 就是欧拉函数的定义:

欧拉函数是指:对于一个正整数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 0xfffffff

using 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;
	}
}



转载于:https://www.cnblogs.com/james1207/p/3424080.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值