HDU1286新朋友欧拉函数版
找新朋友
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10401 Accepted Submission(s):
5493
number,1<CN<10000),接着有CN行正整数N(1<n<32768),表示会员人数。
25608
24027
16016
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新朋友欧拉函数版的更多相关文章
- hdu1286 找新朋友 欧拉函数模板
首先这一题用的是欧拉函数!!函数!!不是什么欧拉公式!! 欧拉函数求的就是题目要求的数. 关于欧拉函数的模板网上百度一下到处都是,原理也容易找,这里要介绍一下另一个强势模板. 在这一题的讨论里看到的. ...
- hdu 1286 找新朋友 欧拉函数模版题
找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem Des ...
- hdu-1286 找新朋友(欧拉函数,水题)
题目链接: 找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- hdu 1286 找新朋友 (欧拉函数)
找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU 1286 找新朋友 (欧拉phi函数打表)
题意:你懂得. 析:一看这个题应该是欧拉phi函数,也就说欧拉phi函数是指求从 1 到 n 中与 n 互素的数的个数,这个题很明显是这个意思嘛,不多说了. 代码如下: #include <io ...
- 【欧拉函数】【HDU1286】 找新朋友
找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- 欧拉函数之HDU1286找新朋友
找新朋友 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submissi ...
- hdu1286(找新朋友)&&POJ2407Relatives(欧拉函数模版题)
http://acm.hdu.edu.cn/showproblem.php?pid=1286 没什么好说的,模板题,主要是弄懂欧拉函数的思想. #include <iostream> #i ...
- 找新朋友---hdu1286(欧拉函数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1286 欧拉函数:对正整数n,欧拉函数是求少于n的数中与n互质的数的数目: 素数(质数)指在一个大于1的 ...
随机推荐
- XCode新建Class时自动加前缀(class prefix 修改前缀)
已经建好的工程,怎么修改class prefix.如图,怎么修改下面的前缀LP,我想改为其他的,比如SH 解决方法: 1.点开Xcode右侧Utilities,Project Document-> ...
- Linux LSM(Linux Security Modules) Hook Technology
目录 . 引言 . Linux Security Module Framework Introduction . LSM Sourcecode Analysis . LSMs Hook Engine: ...
- groovy-集合
Lists 你能使用下面的方法创建一个lists,注意[]是一个空list. 1 def list = [5, 6, 7, 8] 2 assert list.get(2) == 7 3 assert ...
- Message
* Defines a message containing a description and arbitrary data object that can be* sent to a {@link ...
- 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 ...
- 清空file input框
测试环境:OS --> winXPBrowsers --> IE6+, FF 3.0.11, FF 3.5, Opera 9.64, Opera 10 beta 2, Safari 4, ...
- 基于SSH2框架Struts2拦截器的登录验证实现(转)
大象在这里假设你已经弄清楚了Struts2拦截器的基本概念,可以进入实际运用了.那么我们在之前的基础上只需要做下小小的改变,就可以使用Struts2的拦截器机制实现登录的验证. 修改数 ...
- ubuntu查看版本命令
有两种方法 1,cat /etc/issue 2,sudo lsb_release -a 这个查询出来的结果比上面的那个全一些.
- 转>>在同一个sql语句中如何写不同条件的count数量
今天在做Portal中的Dashboard展现的时候,需要对多个统计字段做展现,根据我现在的掌握水平,我只能在sql调用构建器中实现一种sql语 句返回的resultSet做展现.没有办法,只能从数据 ...
- cf.295.C.DNA Alignment(数学推导)
DNA Alignment time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...