GCD Again

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2673    Accepted Submission(s): 1123

Problem Description
Do you have spent some time to think and try to solve those unsolved problem after one ACM contest?
No? Oh, you must do this when you want to become a "Big Cattle".
Now you will find that this problem is so familiar:
The greatest common divisor GCD (a, b) of two positive integers a and b, sometimes written (a, b), is the largest divisor common to a and b. For example, (1, 2) =1, (12, 18) =6. (a, b) can be easily found by the Euclidean algorithm. Now I am considering a little more difficult problem: 
Given an integer N, please count the number of the integers M (0<M<N) which satisfies (N,M)>1.
This is a simple version of problem “GCD” which you have done in a contest recently,so I name this problem “GCD Again”.If you cannot solve it still,please take a good think about your method of study.
Good Luck!
 
Input
Input contains multiple test cases. Each test case contains an integers N (1<N<100000000). A test case containing 0 terminates the input and this test case is not to be processed.
 
Output
For each integers N you should output the number of integers M in one line, and with one line of output for each line in input. 
 
Sample Input
2
4
0
 
Sample Output
0
1
题意:求2到n-1中与n不互质的数的个数,因为欧拉函数求出的是与n互质的数的个数所以用n-el(n)即可,因为大于一所以还要减去1
  1. #include<stdio.h>
  2. #include<string.h>
  3. int el(int n)
  4. {
  5. int i;
  6. int ans=n;
  7. for(i=2;i*i<=n;i++)//用i*i是为了提高运算效率
  8. {
  9. if(n%i==0)
  10. ans=ans/i*(i-1);
  11. while(n%i==0)
  12. n/=i;
  13. }
  14. if(n>1)//为了避免没有运算到1的情况
  15. ans=ans/n*(n-1);
  16. return ans;
  17. }
  18. int main()
  19. {
  20. int n,m,j,i;
  21. while(scanf("%d",&m),m)
  22. {
  23. printf("%d\n",m-el(m)-1);
  24. }
  25. return 0;
  26. }

  

 

hdoj 1787 GCD Again【欧拉函数】的更多相关文章

  1. HDU 1787 GCD Again(欧拉函数,水题)

    GCD Again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  2. hdu 1787 GCD Again (欧拉函数)

    GCD Again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  3. hdu2588 GCD (欧拉函数)

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

  4. uva11426 gcd、欧拉函数

    题意:给出N,求所有满足i<j<=N的gcd(i,j)之和 这题去年做过一次... 设f(n)=gcd(1,n)+gcd(2,n)+......+gcd(n-1,n),那么answer=S ...

  5. HDU 1695 GCD (欧拉函数+容斥原理)

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  6. hdu 4983 Goffi and GCD(欧拉函数)

    Problem Description Goffi is doing his math homework and he finds an equality on his text book: gcd( ...

  7. hdu 1695 GCD(欧拉函数+容斥)

    Problem Description Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD( ...

  8. HDU 1695 GCD(欧拉函数+容斥原理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1695 题意:x位于区间[a, b],y位于区间[c, d],求满足GCD(x, y) = k的(x, ...

  9. GCD(欧拉函数)

    GCD Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissio ...

  10. HDU 2588 GCD(欧拉函数)

    GCD Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

随机推荐

  1. 数据库开发 MySQL

    MySQL是Web世界中使用最广泛的数据库服务器.SQLite的特点是轻量级.可嵌入,但不能承受高并发访问,适合桌面和移动应用.而MySQL是为服务器端设计的数据库,能承受高并发访问,同时占用的内存也 ...

  2. hbuilder工具快捷键 http://www.qq210.com/shoutu/android

    http://www.qq210.com/shoutu/android 创建HTML结构: h 8 (敲h激活代码块列表,按8选择第8个项目,即HTML代码块,或者敲h t Enter)中途换行: ' ...

  3. 自己编写的sublime text 3 插件

    一些小功能,比较杂. 具体的功能在这里查看 1.本地环境的php运行结果获取. 2.快捷打开常用的文件,文件夹,url.(ctrl+shift+a) 3.常用的缩进转换. 下边是网络爬虫代码. #py ...

  4. Leetcode 解题 Longest Substring without repeating charcater python

    原题: Given a string, find the length of the longest substring without repeating character For example ...

  5. ubuntu中vi在编辑状态下方向键不能用的解决

    ubuntu中vi在编辑状态下方向键不能用,还有回格键不能删除等,我们平时习惯的一些键都不能使用. 解决办法: 可以安装vim full版本,在full版本下键盘正常,安装好后同样使用vi命令. 安装 ...

  6. JDBC 基础知识总结

    1.  何谓JDBC  --- Java Database Connectivity. 由Sun 公司提供的访问数据库的一组java类和接口,用来对数据库进行链接.发送SQL语句.处理返回结果,为开发 ...

  7. ArrayList与Vector、HashMap与HashTable

    摘自api: 1.ArrayList与Vector: 原文:This class(ArrayList) is roughly equivalent to Vector, except that it ...

  8. Best Sequence

    poj1699:http://poj.org/problem?id=1699 题意:给你nge串,让你求出这些串组成的最小的串重叠部分只算一次. 题解:我的做法是DFS,因为数据范围只有10,就算是n ...

  9. Delphi XML-RPC 中文乱码解决方法

    http://download.csdn.net/user/csm2432/uploads/2

  10. Maven 的安装配置

    Maven 的安装配置 一.在安装 Maven 之前,先确保JDK1.7及以上版本并且配置好环境变量. 二.下载maven的bin,在apache官方网站可以下载. 1.首先去官网下载 Maven:h ...