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

欧拉函数是指:对于一个正整数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. asp.net MVC中如何用Membership类和自定义的数据库进行登录验证

    asp.net MVC 内置的membershipProvider可以实现用户登陆验证,但是它用的是自动创建的数据库,所以你想用本地数据库数据去验证,是通过不了的. 如果我们想用自己的数据库的话,可以 ...

  2. 【转】android Graphics(四):canvas变换与操作

    android Graphics(四):canvas变换与操作 分类: 5.andriod开发2014-09-05 15:05 5877人阅读 评论(18) 收藏 举报   目录(?)[+]   前言 ...

  3. android xUtils get post

    使用android xUtils框架,进行http的get和post验证. 参考链接: https://github.com/wyouflf/xUtils3 http://blog.csdn.net/ ...

  4. Mybatis的分页插件PageHelper

    Mybatis的分页插件PageHelper 项目地址:http://git.oschina.net/free/Mybatis_PageHelper  文档地址:http://git.oschina. ...

  5. focus 、blur和focusin,focusout的区别

    $('input').focus(function(){///当前元素触发事件(特指表单) }); $('input').blur(function(){//当前元素触发事件 }); $('div') ...

  6. Android shape的使用(圆角矩形)

    <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http: ...

  7. 压测 502 日志报错 upstream timed out (110: Connection timed out)

    环境介绍 服务器:centos6.5服务:nginx proxy 问题描述: 压测 开发同事 的开发环境项目没事,但是 线上机器 命中%50 ,大量502 php的某些页面打不开,页面提示gatewa ...

  8. [ROS]3 Linux编程练习

    一起做RGB-SLAM(2)实验 第二讲 从图像到点云 http://www.cnblogs.com/gaoxiang12/p/4652478.html exbot@ubuntu:~$ cd Code ...

  9. iOS 自定义UITabBarController的tabBar

               #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDeleg ...

  10. 清除mstsc远程登录记录

    这里提供一串清除mstsc远程登录记录的命令 @echo off set TMP1=%cd%echo %TMP1%reg delete "HKEY_CURRENT_USER\Software ...