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. 【windows socket+TCPserverclient】

    Windows Socket+TCPserverclient      Winsock是 Windows下套接字标准.          Socket套接字基于计算机网络,提供同一系统上不同进程或由局 ...

  2. iOS iphone5屏幕适配 autosizing

    转自:http://blog.sina.com.cn/s/blog_a843a8850101jxhh.html iphone5出来了,从不用适配的我们也要像android一样适配不同分辨率的屏幕了. ...

  3. xcode中没有autoSizing的设置

    转自:http://blog.sina.com.cn/s/blog_954bb2f001016oyx.html 学习Xcode的iOS编程时,可能会发现Autosizing Control不见了,其原 ...

  4. Docker大行其道—镜像

    导读 作为Docker三大核心概念之一,Docker镜像(Docker Image)是一个面向Docker引擎的只读模板,包含文件系统.实际上每个Docker镜像包含一个独立的运行环境,如一个镜像包含 ...

  5. mysql服务器的常规操作

    mysql服务器的常规操作 导读 MySQL是一个小型关系数据库管理系统,目前被广泛的应用在Internet上的中小型网站中,体积小.速度快.总体拥有成本低,尤其是开放源码这一特点,使得许多中小型网站 ...

  6. LeetCode31 Next Permutation

    题目: Implement next permutation, which rearranges numbers into the lexicographically next greater per ...

  7. iOS 开发之— NSURLProtocol

    最近在项目里由于电信那边发生dns发生域名劫持,因此需要手动将URL请求的域名重定向到指定的IP地址,但是由于请求可能是通过NSURLConnection,NSURLSession或者AFNetwor ...

  8. Cable master(二分题 注意精度)

    Cable master Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26596   Accepted: 5673 Des ...

  9. Dispatcher中Invoke与BeginInvoke

    [同步]Invoke Application.Current.Dispatcher.Invoke(AutoIncreaseNumber); [异步]BeginInvoke Application.Cu ...

  10. 【Python千问 2】Python核心编程(第二版)-- 欢迎来到Python世界

    1.1 什么是Python 继承了传统编译语言的强大性和通用性,同时也借鉴了简单脚本和解释语言的易用性. 1.2 起源 来源于某个项目,那些程序员利用手边现有的工具辛苦工作着,他们设想并开发了更好的解 ...