Nk 1214 Relatives(欧拉函数)
Time Limit: 1500 ms Memory Limit: 10000 kB
Total Submit : 234 (77 users) Accepted Submit : 102 (72 users) Page View : 3852
Given n, a positive integer, how many positive integers less than n are relatively prime to n? Two integers a and b are relatively prime if there are no integers x > 1, y > 0, z > 0 such that a = xy and b = xz.
Input
Output
Sample Input
7
12
0
Sample Output
6
4
0
AC代码:任何一个整数都能用质因数形式表示如:60=2^2*3^1*5^1 所以for循环中小的质因数被除点剩下从小到大循环中能整除的一定是它质因数
#include<iostream>
#include<cmath>
using namespace std; int euler_phi(int n)
{
int m=sqrt(n+0.5);
int ans=n;
for(int i=2;i<=m;i++)
{
if(n%i==0)
{
ans=ans/i*(i-1);
while(n%i==0)
n/=i;
}
}
if(n>1) ans=ans/n*(n-1);
return ans;
}
int main()
{
int n;
while(cin>>n,n)
cout<<euler_phi(n)<<endl;
return 0;
}
Nk 1214 Relatives(欧拉函数)的更多相关文章
- poj2407 Relatives 欧拉函数基本应用
题意很简单 就是欧拉函数的定义: 欧拉函数是指:对于一个正整数n,小于n且和n互质的正整数(包括1)的个数,记作φ(n) .题目求的就是φ(n) 根据 通式:φ(x)=x*(1-1/p1)*(1-1/ ...
- POJ 2407 Relatives(欧拉函数)
题目链接 题意 : 求小于等于n中与n互质的数的个数. 思路 : 看数学的时候有一部分是将欧拉函数的,虽然我没怎么看懂,但是模板我记得了,所以直接套了一下模板. 这里是欧拉函数的简介. #includ ...
- POJ2407–Relatives(欧拉函数)
题目大意 给定一个正整数n,要求你求出所有小于n的正整数当中与n互质的数的个数 题解 欧拉函数模板题~~~因为n过大~~~所以直接用公式求 代码: #include<iostream> # ...
- POJ 2407 Relatives 欧拉函数题解
版权声明:本文作者靖心,靖空间地址:http://blog.csdn.net/kenden23/,未经本作者同意不得转载. https://blog.csdn.net/kenden23/article ...
- 数论 - 欧拉函数模板题 --- poj 2407 : Relatives
Relatives Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11372 Accepted: 5544 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 ...
- POJ 2407 Relatives 【欧拉函数】
裸欧拉函数. #include<stdio.h> #include<string.h> ; int p[N],pr[N],cnt; void init(){ ;i<N;i ...
- POJ2407 Relatives(欧拉函数)
题目问有多少个小于n的正整数与n互质. 这个可以用容斥原理来解HDU4135.事实上这道题就是求欧拉函数$φ(n)$. $$φ(n)=n(1-1/p_1)(1-1/p_2)\dots(1-1/p_m) ...
- 欧拉函数K - Relatives
欧拉函数是积性函数——若m,n互质,φ(mn)=φ(m)φ(n). 特殊性质:当n为奇数时,φ(2n)=φ(n), φ(x)=x(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)…..( ...
随机推荐
- Mysql 主备配置
来自:http://blog.csdn.net/u013256816/article/details/52536283 1. 了解主备配置过程原理. http://blog.csdn.net/u013 ...
- 为什么字符串String是不可变字符串&&"".equals(str)与str.equals("")的区别
为什么字符串String是不可变字符串 实际上String类的实现是char类型的数组 虽然说源码中设置的是private final char[] value; final关键词表示不可变动 但是只 ...
- java 读取文件转换成字符串
public String readFromFile(File src) { try { BufferedReader bufferedReader = new BufferedReader(new ...
- Mac 安装和卸载 Mysql5.7.11 的方法
安装 去http://www.mysql.com/downloads/, 选择最下方的MySQL Community Edition,点击MySQL Community Server的download ...
- Codeforces Round #277.5 (Div. 2)-D. Unbearable Controversy of Being
http://codeforces.com/problemset/problem/489/D D. Unbearable Controversy of Being time limit per tes ...
- KeyValuePair的使用
Dictionary<string, string> dc = new Dictionary<string, string>(); 前台页面: <div id=" ...
- EXTJS中文乱码
在<head>中加入 <meta http-equiv="Content-Type" content="text/html; charset=GB231 ...
- shell脚本,按单词出现频率降序排序。
[root@localhost oldboy]# cat file the squid project provides a number of resources toassist users de ...
- GSS4 - Can you answer these queries IV || luogu4145上帝造题的七分钟2 / 花神游历各国 (线段树)
GSS4 - Can you answer these queries IV || luogu4145上帝造题的七分钟2 / 花神游历各国 GSS4 - Can you answer these qu ...
- Linux基础学习-Postfix与Dovecot部署邮件系统
电子邮件系统 电子邮件系统是我们在日常工作.生活中最常用的一种网络服务. 部署基础的电子邮件系统 [root@qdlinux ~]# yum install bind-chroot -y [root@ ...