Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 13920   Accepted: 6965

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

Source

 #include<cstdio>
int euler_phi(int p){
int phi=p;
for(int i=;i*i<=p;i++){
if(!(p%i)){
phi=phi-phi/i;
while(!(p%i))
p/=i;
}
}
if(p>)
phi=phi-phi/p;
return phi;
}
int main(){
int p;
while(scanf("%d",&p),p)
printf("%d\n",euler_phi(p));
return ;
}

裸的欧拉函数

 

POJ 2407 Relatives的更多相关文章

  1. POJ 2407 Relatives(欧拉函数)

    http://poj.org/problem?id=2407 题意: 给出一个n,求小于等于的n的数中与n互质的数有几个. 思路: 欧拉函数的作用就是用来求这个的. #include<iostr ...

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

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

  3. POJ 2407 Relatives(欧拉函数入门题)

    Relatives Given n, a positive integer, how many positive integers less than n are relatively prime t ...

  4. POJ 2407 Relatives 【欧拉函数】

    裸欧拉函数. #include<stdio.h> #include<string.h> ; int p[N],pr[N],cnt; void init(){ ;i<N;i ...

  5. POJ 2407 Relatives(欧拉函数)

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

  6. poj 2407 Relatives(简单欧拉函数)

    Description Given n, a positive integer, how many positive integers less than n are relatively prime ...

  7. POJ 2407 Relatives (欧拉函数)

    题目链接 Description Given n, a positive integer, how many positive integers less than n are relatively ...

  8. POJ 2407 Relatives【欧拉函数】

    <题目链接> 题目大意: Given n, a positive integer, how many positive integers less than n are relativel ...

  9. POJ 2407 Relatives 欧拉函数题解

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

随机推荐

  1. Perl 小知识之多行匹配

    如果想匹配多行文本(即文本中有换行符)中的内容,比如: aaa ... bbb ... 要匹配aaa和bbb之间的内容,我们可以使用 /aaa.*bbb/s 其中/s修饰符可以让.匹配任何字符,包括换 ...

  2. 使用Ant命令压缩JavaScript文件

    压缩JavaScript文件可以减少代码尺寸,保护源代码,节省网络带宽,加快页面打开速度,甚至优化JS代码.Yahoo有一个压缩JS的工具叫做YUI compressor, Google也有一个工具叫 ...

  3. 基于sqlite的Qt 数据库封装

    [代码] mydata.h 10 #ifndef MYDATA_H 11 #define MYDATA_H 12 #include <QObject> 13 #include <QS ...

  4. Dockerfile 指令

    FROM 格式为 FROM <image>或FROM <image>:<tag> 第一条指令必须为 FROM 指令.并且,如果在同一个Dockerfile中创建多个 ...

  5. 在使用ICSharpCode.SharpZipLib进行目录压缩后,再解压缩是提示这个错误Size mismatch: 4294967295;126976 70202;126976

    在压缩代码中加入entry.CompressionMethod = CompressionMethod.Stored

  6. Myeclipse2014添加mybatis generator插件

    Myeclipse2014把mybatis generator插件直接放在dropins文件夹下,重启后不能成功安装mybatis插件. 既然离线安装不成功,可以选择在线安装 1.选择 Help-&g ...

  7. 1.6.6 De-Duplication(重复数据删除)

    1. 重复数据删除 solr通过<Signature>类的类型来支持重复数据删除技术的.一个Signature可以通过以下几种方式实现:  方法 描述  MD5Signature  128 ...

  8. Amazon Launches FBA Export to Expand Beyond Media Categories

    Amazon launched a new program called FBA Export for third-party sellers to help them export products ...

  9. 【Open Search产品评测】- 来往,7天轻松定制属于自己的搜索引擎

    [Open Search产品评测]--   来往,7天轻松定制属于自己的搜索引擎   [使用背景] 相信很多人都遇到过要给网站或者app做一个搜索功能的需求,很久之前自己折腾过lucene,搞了很久, ...

  10. 补充:tableView优化总结

    tableView优化方式总结 (说明:一下只是我自己的小总结,会有不足,望大神指正,多谢大家了) 1 缓存 cell 的行高.目的方便第二遍访问 cell. 2 减少图片的blend 操作.包括:设 ...