首先这一题用的是欧拉函数!!函数!!不是什么欧拉公式!!

欧拉函数求的就是题目要求的数。

关于欧拉函数的模板网上百度一下到处都是,原理也容易找,这里要介绍一下另一个强势模板。

在这一题的讨论里看到的。

上题上代码。

-----------------------------------------------------------------------------------

新年快到了,“猪头帮协会”准备搞一个聚会,已经知道现有会员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)
 
 
 #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。

最新文章

  1. [Linux 性能检测工具]PIDSTAT
  2. [leetcode] 根据String数组构造TreeNode,用于LeetCode树结构相关的测试用例
  3. UIkit框架之UIPickerView
  4. 数据库迁移之从oracle 到 MySQL
  5. 斐波那契博弈(Fibonacci Nim)
  6. oracle 问题若干 提醒注意
  7. JAVASCRIPT实现XML分页
  8. android.telephony.SmsManager 短信笔记
  9. nodejs package.json详细解读
  10. DataFrame创建
  11. 如何把Excel中的单元格等对象保存成图片
  12. Linux的安装和使用技巧
  13. Visual Studio 2019 使用 Live Share
  14. Spring AOP实现统一日志输出
  15. 腾讯云服务器tomcat端口无法访问
  16. WPF中任务栏只显示主窗口
  17. conda虚拟环境
  18. python之路 ---计算机硬件基础
  19. C++标准模板库(STL)介绍:string的基本用法
  20. Android忘记锁屏密码如何进入手机?

热门文章

  1. 卡2-SLAM
  2. Linq学习&lt;一&gt;
  3. springMVC工作原理趣味解析
  4. hibernate的几个重要的类和接口
  5. HtmlAgilityPack 使用
  6. 「BJOI2012」连连看
  7. MVN package install error javac: invalid target release: 1.8
  8. 第十一篇 logging模块
  9. 【转】如何不让DataGridView自动生成列
  10. 51nod1832(二叉树/高精度模板+dfs)