hdu1286 找新朋友 欧拉函数模板
首先这一题用的是欧拉函数!!函数!!不是什么欧拉公式!!
欧拉函数求的就是题目要求的数。
关于欧拉函数的模板网上百度一下到处都是,原理也容易找,这里要介绍一下另一个强势模板。
在这一题的讨论里看到的。
上题上代码。
-----------------------------------------------------------------------------------
新年快到了,“猪头帮协会”准备搞一个聚会,已经知道现有会员N人,把会员从1到N编号,其中会长的号码是N号,凡是和会长是老朋友的,那么该会员的号码肯定和N有大于1的公约数,否则都是新朋友,现在会长想知道究竟有几个新朋友?请你编程序帮会长计算出来。
25608
24027
16016
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <iomanip> using namespace std; typedef long long ll;
const int INF = 0x3f3f3f3f;
const int MAXN = ;
const int MOD = 1e9+; int euler(int n)
{
int ret = n;
for(int i = ;i * i <= n;++i)
{
if(n % i == )
{
ret = ret - ret / i;
while(n % i == )
n /= i;
}
}
if(n > )
ret = ret - ret / n;
return ret;
} int main()
{
int T;
cin >>T;
while(T--)
{
int n;
cin >>n;
cout <<euler(n)<<endl;
}
return ;
}
关于if(n > 1):例如n = 12 = 3 * 4,先得到的 i 是2,然后n = 3,就跳出来了,因为循环的判断条件是 i * i <= n。
hdu1286 找新朋友 欧拉函数模板的更多相关文章
- 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) Problem Des ...
- hdu 1286 找新朋友 (欧拉函数)
找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU1286新朋友欧拉函数版
找新朋友 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 ...
- UVA 10820 欧拉函数模板题
这道题就是一道简单的欧拉函数模板题,需要注意的是,当(1,1)时只有一个,其他的都有一对.应该对欧拉函数做预处理,显然不会超时. #include<iostream> #include&l ...
- POJ 2407:Relatives(欧拉函数模板)
Relatives AC代码 Relatives Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16186 Accept ...
- hdu3501Calculation 2——欧拉函数模板
题目: Problem Description Given a positive integer N, your task is to calculate the sum of the positiv ...
- poj2407(欧拉函数模板)
sqrt(n)复杂度 欧拉函数模板 #include <iostream> #include <cstdio> #include <queue> #include ...
随机推荐
- 29.MAX() 函数
MAX() 函数 MAX 函数返回一列中的最大值.NULL 值不包括在计算中. SQL MAX() 语法 SELECT MAX(column_name) FROM table_name 注释:MIN ...
- 安全、结构良好的jQuery结构模板
安全.结构良好的jQuery结构模板 ;(function($,window,document,undefined){ //我们的代码- })(jQuery,window,document); 参 ...
- Codeforces Round #272 (Div. 1) A. Dreamoon and Sums(数论)
题目链接 Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occa ...
- 从程序员角度看ELF
原文:http://xcd.blog.techweb.com.cn/archives/222.html 特殊说明(by jfo) 对于static-linked或shared-linked的ELF可执 ...
- LIRE教程之源码分析 | LIRE Tutorial of Analysis of the Source Code
LIRE教程之源码分析 |LIRE Tutorial of Analysis of the Source Code 最近在做地理图像识别和检索的研究,发现了一个很好用的框架LIRE,遂研究了一通.网上 ...
- 解决linux下80端口占用问题
在即安装有tomcat,又安装有nginx的服务器上(典型阿里云驻云java镜像),系统默认配置nginx占用80端口,tomcat占用8080端口. 如果想要便于用户可以直接通过IP或者域名访问到t ...
- sqlServer基础知识
sqlServer 基础知识 大纲 创建数据库 1 创建表 2 备份表 3 删除表 4 修改表 5 查询出重复的数据 6 增删改查 7 添加约束 8 分页存储过程 9 排序 10 类型转换 11 ...
- Permission denied: .gvfs
$ sudo umount /home/william/.gvfs $ rm -rf ~/.gvfs/ Reference: (Permission denied: .gvfs)[https://an ...
- python-flask之request的属性
flask的request模块的属性(参考) #代码示例,仅仅是为了测试request的属性值 @app.route('/login', methods = ['GET','POST']) def l ...
- react.js学习之路五
最近没时间写博客,但是我一直在学习react,我发现react是一个巨大的坑,而且永远填不完的坑 关于字符串的拼接: 在react中,字符串的拼接不允许出现双引号“” ,只能使用单引号' ',例如这样 ...