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
#include<stdio.h>
#include<string.h>
int el(int n)
{
int i;
int ans=n;
for(i=2;i*i<=n;i++)//用i*i是为了提高运算效率
{
if(n%i==0)
ans=ans/i*(i-1);
while(n%i==0)
n/=i;
}
if(n>1)//为了避免没有运算到1的情况
ans=ans/n*(n-1);
return ans;
}
int main()
{
int n,m,j,i;
while(scanf("%d",&m),m)
{
printf("%d\n",m-el(m)-1);
}
return 0;
}

  

 

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. jquery 放大图片

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. JavaScript的问题

    定义一个函数function, function testParams() { var params = ""; for(var i=0; i<arguments.lengt ...

  3. 查看文章 mysql:表注释和字段注释[转]

    1 创建表的时候写注释 create table test1 ( field_name int comment '字段的注释' )comment='表的注释'; 2 修改表的注释 alter tabl ...

  4. ul动态增加li

    --> aaa bbb <%@ page language="java" import="java.util.*" pageEncoding=&qu ...

  5. 内网DMZ外网之间的访问规则

    当规划一个拥有DMZ的网络时候,我们可以明确各个网络之间的访问关系,可以确定以下六条访问控制策略. 1.内网可以访问外网 内网的用户显然需要自由地访问外网.在这一策略中,防火墙需要进行源地址转换. 2 ...

  6. 【python之路6】pycharm的使用

    1.pycharm简介 PyCharm 是我众多python编辑器中比较好的一个.而且可以跨平台,在macos和windows下面都可以用,这点比较好. PyCharm是一种Python IDE,带有 ...

  7. WebForm中TreeView的使用

    protected void Page_Load(object sender, EventArgs e)        {            DatabaseBind();            ...

  8. m个苹果放在n个筐里,每个筐至少一个,所有的筐都一样,有多少种放法

    package com.study; import java.io.BufferedReader; import java.io.IOException; import java.io.InputSt ...

  9. TFS环境搭建

    这篇文章主要介绍了微软源代码管理工具TFS2013安装与使用图文教程,本文详细的给出了TFS2013的安装配置过程.使用教程,需要的朋友可以参考下 最近公司新开发一个项目要用微软的TFS2013进行项 ...

  10. 【技术帖】解决 Hudson jenkins 连接等待中 - Waiting for next av

    今天构建项目发现如下问题: jenkins 连接等待中 - Waiting for next available executor 左下角那块一直不运行构建,一直在连接等待. 于是,进入一级页面, 右 ...