找新朋友

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10401    Accepted Submission(s):
5493

Problem Description
新年快到了,“猪头帮协会”准备搞一个聚会,已经知道现有会员N人,把会员从1到N编号,其中会长的号码是N号,凡是和会长是老朋友的,那么该会员的号码肯定和N有大于1的公约数,否则都是新朋友,现在会长想知道究竟有几个新朋友?请你编程序帮会长计算出来。
 
Input
第一行是测试数据的组数CN(Case
number,1<CN<10000),接着有CN行正整数N(1<n<32768),表示会员人数。
 
Output
对于每一个N,输出一行新朋友的人数,这样共有CN行输出。
 
Sample Input
2
25608
24027
 
Sample Output
7680
16016
 
Author
SmallBeer(CML)
 
Source
 
Recommend
lcy   |   We have carefully selected several similar
problems for you:  1215 1406 1164 1787 1211 

i代表质数 非质数不跑 res代表剩下的数 就是答案的数 x代表质因子分解的数 从x中分解出质因子进行运用
用完2要把2的倍数去掉所以有while那句话。

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <math.h>
using namespace std;
int euler(int x)
{// 就是公式
int i, res=x;
for (i = ; i < (int)sqrt(x * 1.0) + ; i++)
if(x%i==)
{
cout<<"start i:"<<i<<" res:"<<res<<" x:"<<x<<endl;
res = res / i * (i - );
cout<<"delete i:"<<i<<" res:"<<res<<" x:"<<x<<endl;
while (x % i == ) {x /= i;cout<<"x%i==0 i:"<<i<<" res:"<<res<<" x:"<<x<<endl;} // 保证i一定是素数
cout<<endl;
} if (x > ) {res = res / x * (x - );cout<<"end i:"<<i<<" res:"<<res<<" x:"<<x<<endl;}
return res;
}
int main()
{
int n,t;
cin>>t;
while(t--)
{cin>>n;
cout<<euler(n)<<endl;}
return ;
}

HDU1286新朋友欧拉函数版的更多相关文章

  1. hdu1286 找新朋友 欧拉函数模板

    首先这一题用的是欧拉函数!!函数!!不是什么欧拉公式!! 欧拉函数求的就是题目要求的数. 关于欧拉函数的模板网上百度一下到处都是,原理也容易找,这里要介绍一下另一个强势模板. 在这一题的讨论里看到的. ...

  2. hdu 1286 找新朋友 欧拉函数模版题

    找新朋友 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem Des ...

  3. hdu-1286 找新朋友(欧拉函数,水题)

    题目链接: 找新朋友 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  4. hdu 1286 找新朋友 (欧拉函数)

    找新朋友 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  5. HDU 1286 找新朋友 (欧拉phi函数打表)

    题意:你懂得. 析:一看这个题应该是欧拉phi函数,也就说欧拉phi函数是指求从 1 到 n 中与 n 互素的数的个数,这个题很明显是这个意思嘛,不多说了. 代码如下: #include <io ...

  6. 【欧拉函数】【HDU1286】 找新朋友

    找新朋友 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  7. 欧拉函数之HDU1286找新朋友

    找新朋友 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submissi ...

  8. hdu1286(找新朋友)&&POJ2407Relatives(欧拉函数模版题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1286 没什么好说的,模板题,主要是弄懂欧拉函数的思想. #include <iostream> #i ...

  9. 找新朋友---hdu1286(欧拉函数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1286 欧拉函数:对正整数n,欧拉函数是求少于n的数中与n互质的数的数目: 素数(质数)指在一个大于1的 ...

随机推荐

  1. XCode新建Class时自动加前缀(class prefix 修改前缀)

    已经建好的工程,怎么修改class prefix.如图,怎么修改下面的前缀LP,我想改为其他的,比如SH 解决方法: 1.点开Xcode右侧Utilities,Project Document-> ...

  2. Linux LSM(Linux Security Modules) Hook Technology

    目录 . 引言 . Linux Security Module Framework Introduction . LSM Sourcecode Analysis . LSMs Hook Engine: ...

  3. groovy-集合

    Lists 你能使用下面的方法创建一个lists,注意[]是一个空list. 1 def list = [5, 6, 7, 8] 2 assert list.get(2) == 7 3 assert  ...

  4. Message

    * Defines a message containing a description and arbitrary data object that can be* sent to a {@link ...

  5. Oracle 11g ORA-00845: MEMORY_TARGET not supported on this system

    启动Oracle 11gR2后报错:ORA-00845 rac1:/home/oracle> sqlplus / as sysdba; SQL*Plus: Release 11.2.0.3.0 ...

  6. 清空file input框

    测试环境:OS --> winXPBrowsers --> IE6+, FF 3.0.11, FF 3.5, Opera 9.64, Opera 10 beta 2, Safari 4, ...

  7. 基于SSH2框架Struts2拦截器的登录验证实现(转)

        大象在这里假设你已经弄清楚了Struts2拦截器的基本概念,可以进入实际运用了.那么我们在之前的基础上只需要做下小小的改变,就可以使用Struts2的拦截器机制实现登录的验证.     修改数 ...

  8. ubuntu查看版本命令

    有两种方法 1,cat /etc/issue 2,sudo lsb_release -a 这个查询出来的结果比上面的那个全一些.

  9. 转>>在同一个sql语句中如何写不同条件的count数量

    今天在做Portal中的Dashboard展现的时候,需要对多个统计字段做展现,根据我现在的掌握水平,我只能在sql调用构建器中实现一种sql语 句返回的resultSet做展现.没有办法,只能从数据 ...

  10. cf.295.C.DNA Alignment(数学推导)

    DNA Alignment time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...