Relatives

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

Description

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的数据比较大,不用筛选法打欧拉函数表,直接用公式:

  


 //2016.8.17
#include<iostream>
#include<cstdio> using namespace std; int phi(int n)
{
int ans = n;
for(int i = ; i <= n; i++)
{
if(n%i==)
{
ans -= ans/i;
while(n%i==)
n /= i;
}
if(n == )break;
}
return ans;
} int main()
{
int n;
while(cin>>n&&n)
{
cout<<phi(n)<<endl;
} return ;
}

POJ2407(欧拉函数)的更多相关文章

  1. poj2407(欧拉函数模板)

    sqrt(n)复杂度 欧拉函数模板 #include <iostream> #include <cstdio> #include <queue> #include ...

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

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

  3. POJ2407 Relatives(欧拉函数)

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

  4. poj2407 Relatives 欧拉函数基本应用

    题意很简单 就是欧拉函数的定义: 欧拉函数是指:对于一个正整数n,小于n且和n互质的正整数(包括1)的个数,记作φ(n) .题目求的就是φ(n) 根据 通式:φ(x)=x*(1-1/p1)*(1-1/ ...

  5. POJ2407–Relatives(欧拉函数)

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

  6. 51Nod 1136 欧拉函数 Label:数论

    对正整数n,欧拉函数是少于或等于n的数中与n互质的数的数目.此函数以其首名研究者欧拉命名,它又称为Euler's totient function.φ函数.欧拉商数等.例如:φ(8) = 4(Phi( ...

  7. hdu1286(找新朋友)&&POJ2407Relatives(欧拉函数模版题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1286 没什么好说的,模板题,主要是弄懂欧拉函数的思想. #include <iostream> #i ...

  8. hdu2588 GCD (欧拉函数)

    GCD 题意:输入N,M(2<=N<=1000000000, 1<=M<=N), 设1<=X<=N,求使gcd(X,N)>=M的X的个数.  (文末有题) 知 ...

  9. BZOJ 2705: [SDOI2012]Longge的问题 [欧拉函数]

    2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 2553  Solved: 1565[Submit][ ...

随机推荐

  1. Extjs4---Cannot read property 'addCls' of null - heirenheiren的专栏 - 博客频道 - CSDN.NET

    body { font-family: 微软雅黑,"Microsoft YaHei", Georgia,Helvetica,Arial,sans-serif,宋体, PMingLi ...

  2. 计算机学院大学生程序设计竞赛(2015’12) 1005 Bitwise Equations

    #include<cmath> #include<cstdio> #include<cstring> #include<algorithm> using ...

  3. C#WinForm中复制、粘贴文本到剪贴板

    //复制: private void button1_Click(object sender, System.EventArgs e) {   if(textBox1.SelectedText != ...

  4. HttpServletRequest.getServletContext()一直提示找不到,而引出的问题

    开发j2ee项目的时候,需要用到servlet-api,如果使用了maven,web项目可以在pom.xml中手动加入所需jar包,达到与依赖j2ee libarary同样的功能.可问题来了: 1. ...

  5. hibernate---树状映射

    总公司--分公司1, 分公司2 分公司1: 分公司1下部门1, 分公司1下部门2 分公司2: Org.java: package com.bjsxt.hibernate; import java.ut ...

  6. postgresql 数据库的备份和恢复 (pg_dump 和 pg_restore)

    pg_dump 用来备份数据库: pg_restore 用来恢复数据库: 备份出来的文件可以用 XZ (linux 自带的压缩工具压缩). XZ压缩最新压缩率之王 xz这个压缩可能很多都很陌生,不过您 ...

  7. 链接器工具错误 LNK1123

    由于新学C++变成,找不到人求教,所以这个问题困扰了我很久,今天终于找到终极解决方案了: 出处,此帖25楼: http://bbs.csdn.net/topics/390121452 终极解决方案:V ...

  8. location下的属性集锦

    location.protocol="http:"//即,协议 location.hostname="zhidao.baidu.com"//即,主机域名

  9. 解决phpcms V9缩略图模糊的方法

    解决V9缩略图模糊/libs/classes/image.class.php注释掉else   imagecopyresized($thumbimg, $srcimg, 0, 0, $psrc_x,  ...

  10. 自己实现的sax XML解析,可能会有误

    package com.agatha.bean; public class OrderInfoBean { private String order_id; private String room_t ...