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

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

poj2407 Relatives 欧拉函数基本应用的更多相关文章

  1. POJ2407–Relatives(欧拉函数)

    题目大意 给定一个正整数n,要求你求出所有小于n的正整数当中与n互质的数的个数 题解 欧拉函数模板题~~~因为n过大~~~所以直接用公式求 代码: #include<iostream> # ...

  2. poj2407(欧拉函数模板题)

    题目链接:https://vjudge.net/problem/POJ-2407 题意:给出n,求0..n-1中与n互质的数的个数. 思路:欧拉函数板子题,先根据唯一分解定理求出n的所有质因数p1,p ...

  3. POJ 2407 Relatives(欧拉函数)

    题目链接 题意 : 求小于等于n中与n互质的数的个数. 思路 : 看数学的时候有一部分是将欧拉函数的,虽然我没怎么看懂,但是模板我记得了,所以直接套了一下模板. 这里是欧拉函数的简介. #includ ...

  4. POJ 2407 Relatives 欧拉函数题解

    版权声明:本文作者靖心,靖空间地址:http://blog.csdn.net/kenden23/,未经本作者同意不得转载. https://blog.csdn.net/kenden23/article ...

  5. POJ2407 Relatives(欧拉函数)

    题目问有多少个小于n的正整数与n互质. 这个可以用容斥原理来解HDU4135.事实上这道题就是求欧拉函数$φ(n)$. $$φ(n)=n(1-1/p_1)(1-1/p_2)\dots(1-1/p_m) ...

  6. 数论 - 欧拉函数模板题 --- poj 2407 : Relatives

    Relatives Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11372   Accepted: 5544 Descri ...

  7. POJ2407(欧拉函数)

    Relatives Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13598   Accepted: 6771 Descri ...

  8. POJ 2407 Relatives(欧拉函数入门题)

    Relatives Given n, a positive integer, how many positive integers less than n are relatively prime t ...

  9. POJ 2407:Relatives(欧拉函数模板)

    Relatives AC代码 Relatives Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16186   Accept ...

随机推荐

  1. ul和ol的一些知识

    ul和ol的一些知识 div#div0 ul{ border:1px solid #ccc; list-style:none; } div#div0 ul li{ border:1px solid g ...

  2. iOS 的 XMPPFramework 简介

    XMPPFramework是一个OS X/iOS平台的开源项目,使用Objective-C实现了XMPP协议(RFC-3920),同时还提供了用于读写XML的工具,大大简化了基于XMPP的通信应用的开 ...

  3. Apache中压力测试工具ab的操作说明

    1.压力测试工具ab(ApacheBench)的简单说明 1)     网站性能压力测试是性能调优过程中必不可少的一环.只有让服务器处在高压情况下才能真正体现出各种设置所暴露的问题.Apache中有个 ...

  4. 56个睿智帅气貌美的CTO大牛陪你叨逼叨

    技术领域门槛高,苦读十年有时不如大牛一指点 可CTO级别的大牛何处找? 别急,别急 他们1月12日都去参加APICloud新品发布会了! (没图说啥子) 各路大牛们云集,不仅是为APICloud新品发 ...

  5. 敏捷BI——岂止于快

    信息爆炸的时代,唯有分析快,才可以把握住可能分分钟流失的数据信息,唯有钻取深,才可以挖掘出海量信息中蕴藏的财富.是时候为您的企业上一套敏捷BI了. [敏捷BI的产生背景] 传统BI由IT人员做报表,业 ...

  6. vmware虚拟机三种网络模式详解_转

    原文来自http://note.youdao.com/share/web/file.html?id=236896997b6ffbaa8e0d92eacd13abbf&type=note 由于L ...

  7. Linux 创建用户和工作组

    创建用户 useradd user1                            #创建user1用户,创建user1用户同时会创建一个同名的工作组user1 passwd user1   ...

  8. Vue.2.0.5-单文件组件

    介绍 在很多Vue项目中,我们使用 Vue.component 来定义全局组件,紧接着用new Vue({ el: '#container '}) 在每个页面内指定一个容器元素. 这种方案在只是使用 ...

  9. NSCoding归档

    大家都知道ios中数据持久化的方式有plist sqlite coredata nscoding 而nscoding不需要关心模型属性有多少个,是什么类型,不需要定义归档文件的规则. 下面给个类大家用 ...

  10. Leetcode: Increasing Triplet Subsequence

    Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...