GCD Again

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

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
 水题一枚
#include <stdio.h>
#include <string.h>
using namespace std;
typedef long long LL;
LL phi(LL x)
{
LL ans=x;
for(LL i=; i*i<=x; i++)
if(x%i==)
{
ans=ans/i*(i-);
while(x%i==) x/=i;
}
if(x>)
ans=ans/x*(x-);
return ans;
} int main(){
LL n;
while(scanf("%lld",&n)!=EOF,n){
printf("%lld\n",n-phi(n)-);
}
}

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

  1. hdu 6390 欧拉函数+容斥(莫比乌斯函数) GuGuFishtion

    http://acm.hdu.edu.cn/showproblem.php?pid=6390 题意:求一个式子 题解:看题解,写代码 第一行就看不出来,后面的sigma公式也不会化简.mobius也不 ...

  2. hdu 2654(欧拉函数)

    Become A Hero Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  3. hdu 2824(欧拉函数)

    The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  4. hdu 1395(欧拉函数)

    2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  5. hdu 3307(欧拉函数+好题)

    Description has only two Sentences Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/327 ...

  6. 找新朋友 HDU - 1286 欧拉函数模板题

    题意: 求出来区间[1,n]内与n互质的数的数量 题解: 典型的欧拉函数应用,具体见这里:Relatives POJ - 2407 欧拉函数 代码: 1 #include<stdio.h> ...

  7. hdu 2824 欧拉函数 O(nlogn) 和O(n)

    裸题 O(nlogn): #include <cstdio> #include <iostream> #include <algorithm> using name ...

  8. hdu 4983 欧拉函数

    http://acm.hdu.edu.cn/showproblem.php?pid=4983 求有多少对元组满足题目中的公式. 对于K=1的情况,等价于gcd(A, N) * gcd(B, N) = ...

  9. hdu 4002 欧拉函数 2011大连赛区网络赛B

    题意:求1-n内最大的x/phi(x) 通式:φ(x)=x*(1-1/p1)*(1-1/p2)*(1-1/p3)*(1-1/p4)…..(1-1/pn),其中p1, p2……pn为x的所有质因数,x是 ...

随机推荐

  1. pandas关联mysql并读写数据库

    1.代码读写mysql,必须安装关联mysql的工具 操作如下命令: sudo apt-get install mysql-server mysql-clientsudo apt-get instal ...

  2. python入门:输出1-10的所有数

    #!/usr/bin/env python # -*- coding:utf-8 -*- #输出1-10的所有数 """ 变量kaishi的赋值为数字1,while 真, ...

  3. mybatis枚举类型处理器

    1. 定义枚举值的接口 public abstract interface ValuedEnum { int getValue(); } 所有要被mybatis处理的枚举类继承该接口 2. 定义枚举类 ...

  4. mysql的字符串连接符

    以前用SQL Server 连接字符串是用“+”,现在数据库用mysql,写个累加两个字段值SQL语句居然不支持"+",郁闷了半天在网上查下,才知道mysql里的+是数字相加的操作 ...

  5. 如何使用 HTML5 的picture元素处理响应式图片

    来自: http://www.w3cplus.com/html5/quick-tip-how-to-use-html5-picture-for-responsive-images.html 图片在响应 ...

  6. IOC容器和Bean的配置

     IOC容器和Bean的配置   1        IOC和DI ①IOC(Inversion of Control):反转控制. 在应用程序中的组件需要获取资源时,传统的方式是组件主动的从容器中获取 ...

  7. HDU 3486 Interviewe RMQ

    题意: 将\(n\)个数分成\(m\)段相邻区间,每段区间的长度为\(\left \lfloor \frac{n}{m} \right \rfloor\),从每段区间选一个最大值,要让所有的最大值之和 ...

  8. 缓存淘汰算法之LRU实现

    Java中最简单的LRU算法实现,就是利用 LinkedHashMap,覆写其中的removeEldestEntry(Map.Entry)方法即可 如果你去看LinkedHashMap的源码可知,LR ...

  9. phpcms调用一个指定的栏目

    很多初学者在学习phpcms的时候在模板中都是静态的写导航的url,那样在后期维护的时候可是个巨大的工程啊,所以我在学的时候就想起织梦是能指定调用栏目的url,借鉴了这一想法, {$CATEGORY[ ...

  10. iis上的反向代理

    阅读文章: IIS上的反向代理 ARR(Application Request Routing)