Relatives

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

There are several test cases. For each test case, standard input contains a line with n <= 1,000,000,000. A line containing 0 follows the last case.

Output

For each test case there should be single line of output answering the question posed above.
 
Sample Input

7
12
0

Sample Output

6
4 题意:输入个n,求(1,n-1)与n互质的个数有多少个
思路:这明显就是欧拉函数模版题,就是求n的欧拉数
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
ll phi(ll n)//求n的欧拉数
{
ll sum=n;
for(int i=;i*i<=n;i++)//O(根号n的复杂度)
{
if(n%i==)
{
sum=sum-sum/i;
do
{
n/=i;
}while(n%i==);
}
}
if(n>) sum=sum-sum/n;
return sum;
}
int main()
{
ll n;
while(scanf("%lld",&n)!=EOF)
{
if(n==)
break;
printf("%lld\n",phi(n));
}
}
 

POJ 2407 Relatives(欧拉函数入门题)的更多相关文章

  1. POJ 2407 Relatives(欧拉函数)

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

  2. POJ 2407 Relatives 欧拉函数题解

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

  3. POJ2407–Relatives(欧拉函数)

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

  4. UVA 10820 欧拉函数模板题

    这道题就是一道简单的欧拉函数模板题,需要注意的是,当(1,1)时只有一个,其他的都有一对.应该对欧拉函数做预处理,显然不会超时. #include<iostream> #include&l ...

  5. hdu 1286 找新朋友 欧拉函数模版题

    找新朋友 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem Des ...

  6. (hdu step 7.2.1)The Euler function(欧拉函数模板题——求phi[a]到phi[b]的和)

    题目: The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...

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

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

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

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

  9. 【poj 2407】Relatives(数论--欧拉函数 模版题)

    题意就是求10^9以内的正整数的欧拉函数(Φ(n)表示<=n的与n互质的正整数个数). 解法:用欧拉筛和欧拉函数的一些性质:    1.若p是质数,Φ(p)=p-1:    2.欧拉函数是积性函 ...

随机推荐

  1. Div不用float布局

    CSS代码 .wrapper1_4 { width: 100%; /* 也可以固定宽度 */ height: 26px; } .wrapper1_4 > .left { display: inl ...

  2. django 中基于类的视图

    django 视图 分为两种: 1.  FBV  基于函数的视图      function   based  view 2.  CBV  基于类的视图         class   based  ...

  3. apiCloud 双击事件

    apiCloud 双击事件只能使用纯js去写 var app = new Vue({ el: "#app", data: function() { return { token: ...

  4. 4.1.3 Euclid's Game (POJ 2348)

    Problem description: 以辗转相除法为基础,给定两个整数a和b,Stan和Ollie轮流从较大的数字中减去较小数字的倍数(整倍数),并且相减后的结果不能为零.Stan先手,在自己的回 ...

  5. 最长回文字串——manacher算法

    时间复杂度:O(n) 参考:https://segmentfault.com/a/1190000003914228 1.问题定义 最长回文子串问题:给定一个字符串,求它的最长回文子串长度. 如果一个字 ...

  6. DVWA-CSRF

    Low等级   image 抓包   image 正常跳转   image   image 在这里我们把密码改为qwer   image   image   image   image   image ...

  7. win8.1安装密钥

    https://zhidao.baidu.com/question/374064869043943484.html

  8. Hadoop 2.7.3 完全分布式维护-简单测试篇

    1. 测试MapReduce Job 1.1 上传文件到hdfs文件系统 $ jps Jps SecondaryNameNode JobHistoryServer NameNode ResourceM ...

  9. PostgreSQL常用函数

    1.系统信息函数 1.会话信息函数 edbstore=# select current_catalog; #查询当前数据库名称 current_database ------------------ ...

  10. 字符序列(characts)

    字符序列(characts) 问题描述: 从三个元素的集合[A,B,C]中选取元素生成一个N 个字符组成的序列,使得没有两个相邻的 子序列(子序列长度=2)相同,例:N=5 时ABCBA 是合格的,而 ...