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;
}
}
poj2407 Relatives 欧拉函数基本应用的更多相关文章
- POJ2407–Relatives(欧拉函数)
题目大意 给定一个正整数n,要求你求出所有小于n的正整数当中与n互质的数的个数 题解 欧拉函数模板题~~~因为n过大~~~所以直接用公式求 代码: #include<iostream> # ...
- poj2407(欧拉函数模板题)
题目链接:https://vjudge.net/problem/POJ-2407 题意:给出n,求0..n-1中与n互质的数的个数. 思路:欧拉函数板子题,先根据唯一分解定理求出n的所有质因数p1,p ...
- POJ 2407 Relatives(欧拉函数)
题目链接 题意 : 求小于等于n中与n互质的数的个数. 思路 : 看数学的时候有一部分是将欧拉函数的,虽然我没怎么看懂,但是模板我记得了,所以直接套了一下模板. 这里是欧拉函数的简介. #includ ...
- POJ 2407 Relatives 欧拉函数题解
版权声明:本文作者靖心,靖空间地址:http://blog.csdn.net/kenden23/,未经本作者同意不得转载. https://blog.csdn.net/kenden23/article ...
- POJ2407 Relatives(欧拉函数)
题目问有多少个小于n的正整数与n互质. 这个可以用容斥原理来解HDU4135.事实上这道题就是求欧拉函数$φ(n)$. $$φ(n)=n(1-1/p_1)(1-1/p_2)\dots(1-1/p_m) ...
- 数论 - 欧拉函数模板题 --- poj 2407 : Relatives
Relatives Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11372 Accepted: 5544 Descri ...
- POJ2407(欧拉函数)
Relatives Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13598 Accepted: 6771 Descri ...
- POJ 2407 Relatives(欧拉函数入门题)
Relatives Given n, a positive integer, how many positive integers less than n are relatively prime t ...
- POJ 2407:Relatives(欧拉函数模板)
Relatives AC代码 Relatives Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16186 Accept ...
随机推荐
- JMeter学习-006-Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002 解决办法(windows 7)
好久没用 JMeter 了,今天启动的时候,发现启动命令行窗口出现了警报,警告信息如下图所示:
- 微信支付开发(11) Native支付
关键字:微信公众平台 微信支付 Native原生支付作者:方倍工作室原文:http://www.cnblogs.com/txw1958/p/wxpay-native.html 由于微信支付接口更新,本 ...
- Access数据库创建、使用
1.创建Access数据库表 1)在office中打开Microsoft Access2010,选择空数据库创建数据库StudentInfo. 2)创建新表,在表格第一列选择数据类型,并输入列名. 3 ...
- Speed-BI云平台正在公测中,欢迎大家体验!
Speed-BI云平台正在公测中,欢迎大家体验.访问地址:http://speedbi.cn 支持IE(建议IE8以上),Edge,Chrome,Firefox,Safari等任意浏览器,以及采用这几 ...
- SUSE Linux 防火墙设置
1.vim /etc/sysconfig/SuSEfirewall2 #编辑防火墙设置 FW_SERVICES_EXT_TCP="22 5901" #开启 ...
- hadoop wordcount
Mapper // map的数量与数的分片有关系 public class WCMapper extends Mapper<LongWritable, Text, Text, LongWrita ...
- Spring Security HTTP Basic for RESTFul and FormLogin (Cookies) for web - Annotations
@Configuration @EnableWebMvcSecurity @EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabl ...
- Java基础之线程——管理线程同步方法(BankOperation2)
控制台程序. 当两个或多个线程共享同一资源时,例如文件或内存块,就需要采取措施,确保其中的一个线程不会修改另一个线程正在使用的资源.当其中的一个线程更新文件中的某个记录,同时另一个线程正在检索这个记录 ...
- Redis分布式
昨天公司技术大牛做了一个Redis分布式的技术分享: Redis分布式资源: http://redis.io/topics/cluster-tutorialhttp://redis.io/topics ...
- Leetcode: Majority Element II
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorit ...