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且与n互质的数的个数。

AC代码:

 #include<bits/stdc++.h>
using namespace std;
int Euler(int x){
int r=x;
for(int i=;i*i<=x;i++){//由于任何一个合数都至少有一个不大于根号x的质因子,所以只需遍历到根号x即可
if(x%i==){
r=r/i*(i-);//欧拉函数的通式,先除后乘,避免数据溢出
while(x%i==)x/=i;//消除x中所有质因子i,直到不能被i整除
}
}
if(x>)r=r/x*(x-);//如果x大于1,说明还有一个质因子没有除掉
return r;//返回个数
}
int main(){
int n;
while(cin>>n&&n)
cout<<Euler(n)<<endl;
return ;
}

最新文章

  1. DAC Usage2:通过DAC实现DB Schema的Migration和Upgrade
  2. IOS开发之显示微博表情
  3. 背景建模post_processing常用opencv函数(怒了)
  4. Spring mvc 中使用ftl引用共通文件出错 FreeMarker template error: Error reading included file &quot;/WEB-INF/ftl/common/errormessage.ftl&quot;
  5. pip卡住不动的解决方案
  6. Design and Analysis of Algorithms_Introduction
  7. Android中的sp与wp
  8. Http下的各种操作类.WebApi系列~通过HttpClient来调用Web Api接口
  9. HTML5元素拖拽实现示例
  10. android获得屏幕高度和宽度
  11. [布局]bootstrap基本标签总结2
  12. 黑马程序员 ——Java SE(1)
  13. 团队作业4----第一次项目冲刺(Alpha版本)4.25
  14. Asynchronous vs synchronous client applications(MQTT)
  15. python全栈学习--day3
  16. jacascript JSON对象的学习
  17. Springboot 系列(九)使用 Spring JDBC 和 Druid 数据源监控
  18. 【Unity】6.5 Time类、Mathf类、Coroutine类
  19. dubbo provider如何对invoker进行export
  20. Bootloader的结构和启动过程

热门文章

  1. ci框架(codeigniter)Email发送邮件、收件人、附件、Email调试工具
  2. POJ 3320_Jessica&#39;s Reading Problem
  3. NOIP 2010 乌龟棋
  4. Android GIS开发系列-- 入门季(14)FeatureLayer之范围查询
  5. mysql建表语句key的含义
  6. HDU 1796 How many integers can you find(容斥原理+二进制/DFS)
  7. Eclipse或SVN—怎样在Eclipse中安装SVNclient插件
  8. C# 实现WEBSOCKET聊天应用示例
  9. 使用fiddler将网站上的css js重定向至本地文件
  10. JAVA 并发编程-读写锁之模拟缓存系统(十一)