众所周知 若(n,x)= 1,则 (n,n-x)=1;

所以只需求出n的欧拉函数值,则1~n-1中与n互素的和为m = Euler(n)* n  / 2;

那么不互素的和为n*(n-1)/ 2  - m;

#include<stdio.h>
#include<math.h>
typedef __int64 LL;
const LL mod = 1000000007;
LL Euler(LL x)
{LL res = x;for(int i = 2;i <= sqrt(x);i++){if(x%i==0){while(x%i==0) x/=i;res = res/i*(i-1)%mod;}}if(x > 1) res = res/x*(x-1)%mod;return res;
}
int main()
{LL n;while(scanf("%I64d",&n),n){LL m = Euler(n);printf("%I64d\n",(((n*(n-1)/2)%mod - m*n/2%mod)+mod)%mod);}
}

hdu-Calculation 2(欧拉函数)相关推荐

  1. hdu 4983(欧拉函数)

    题目大意:给出一组n和k,求解满足公式:gcd(n-a,n)*gcd(n-b,n)=n^k的(a,b)的对数,结果对(1e9+7)取模. 先证明:对于1<=x<=n,有gcd(n-x , ...

  2. HDU 5514 Frogs 欧拉函数

    题意: 有\(m(1 \leq m \leq 10^9)\)个石子排成一圈,编号分别为\(0,1,2 \cdots m-1\). 现在在\(0\)号石头上有\(n(1 \leq n \leq 10^4 ...

  3. HDU 2588 GCD(欧拉函数)

    GCD 思路 题目要求,对于给定的n,mn, mn,m要求有多少数∑i=1ngcd(i,n)>=m\sum _{i = 1} ^{n} gcd(i, n) >= m∑i=1n​gcd(i, ...

  4. hdu 1286( 欧拉函数 )

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1286 数学题真的是有点吃不消了... View Code 1 #include<iostream ...

  5. hdu (欧拉函数+容斥原理) GCD

    题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1695 看了别人的方法才会做 参考博客http://blog.csdn.net/shiren_Bod/ar ...

  6. HDU 1286 找新朋友 (欧拉函数)

    找新朋友 http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2&sectionid=1&problemid=8 T ...

  7. (hdu step 7.2.1)The Euler function(欧拉函数模板题——求phi[a]到phi[b]的和)

    题目: The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...

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

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

  9. hdu 3501 欧拉函数

    容易想到容斥原理,但是结合欧拉函数的公式,我们得到: 小于n且与n互质的数的和为:n * phi(n) / 2 于是问题迎刃而解. 1 #include <iostream> 2 #inc ...

  10. hdu 4983 Goffi and GCD(欧拉函数)

    Problem Description Goffi is doing his math homework and he finds an equality on his text book: gcd( ...

最新文章

  1. 【SRM 716 DIV 1 A】 ConstructLCS
  2. 我的思维模式的阿喀琉斯之踵
  3. Mockito对final类型和方法的支持(三):免配置的inline mock making
  4. r语言默认工作目录document_使用 Docker 和 Nginx 实现简单目录索引服务
  5. 英雄联盟怎么解除小窗口_英雄联盟手游怎么加好友_英雄联盟手游怎么加好友一起玩_资讯...
  6. Oracle 的 Sql*Plus 常用命令介绍
  7. 【数据科学系统学习】机器学习算法 # 西瓜书学习记录 [8] 支持向量机(二)...
  8. wildfly access log 开启
  9. javascript 函数2——对象排序
  10. fft与fftshift的维度
  11. cc1101 使用笔记
  12. 电路串联和并联图解_判断串联并联电路图口诀
  13. 620集成显卡和mx250_MX250属于什么档次的显卡
  14. sin30的c语言表达式,c语言sin30度怎么打
  15. 8.2 知识蒸馏方法概述
  16. anaconda安装多环境
  17. 洛谷P3987 我永远喜欢珂朵莉~(set 树状数组)
  18. 有关C#中重写按钮的onpaint函数,实现按钮形状的用户自定义
  19. Windows时钟同步(时间同步)问题
  20. Gdal关于CAD转SHP格式

热门文章

  1. 网易来聊聊子弹短信的消息漫游技术
  2. consul 1.2 支持service mesh
  3. 黄聪:visual studio 2017编译运行出现脚本发生错误等问题如何解决?
  4. android trace文件分析ANR
  5. HDU 2498 Digits
  6. mongodb分片配置
  7. m2eclipse插件
  8. RDIFramework.NET ━ .NET快速信息化系统开发框架-4.3 平台主界面
  9. 使用Windows8开发Metro风格应用五
  10. 实验0-Hive配置与启动