hdu-Calculation 2(欧拉函数)
众所周知 若(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(欧拉函数)相关推荐
- hdu 4983(欧拉函数)
题目大意:给出一组n和k,求解满足公式:gcd(n-a,n)*gcd(n-b,n)=n^k的(a,b)的对数,结果对(1e9+7)取模. 先证明:对于1<=x<=n,有gcd(n-x , ...
- HDU 5514 Frogs 欧拉函数
题意: 有\(m(1 \leq m \leq 10^9)\)个石子排成一圈,编号分别为\(0,1,2 \cdots m-1\). 现在在\(0\)号石头上有\(n(1 \leq n \leq 10^4 ...
- HDU 2588 GCD(欧拉函数)
GCD 思路 题目要求,对于给定的n,mn, mn,m要求有多少数∑i=1ngcd(i,n)>=m\sum _{i = 1} ^{n} gcd(i, n) >= m∑i=1ngcd(i, ...
- hdu 1286( 欧拉函数 )
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1286 数学题真的是有点吃不消了... View Code 1 #include<iostream ...
- hdu (欧拉函数+容斥原理) GCD
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1695 看了别人的方法才会做 参考博客http://blog.csdn.net/shiren_Bod/ar ...
- HDU 1286 找新朋友 (欧拉函数)
找新朋友 http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2§ionid=1&problemid=8 T ...
- (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 ...
- hdu 1286 找新朋友 欧拉函数模版题
找新朋友 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem Des ...
- hdu 3501 欧拉函数
容易想到容斥原理,但是结合欧拉函数的公式,我们得到: 小于n且与n互质的数的和为:n * phi(n) / 2 于是问题迎刃而解. 1 #include <iostream> 2 #inc ...
- hdu 4983 Goffi and GCD(欧拉函数)
Problem Description Goffi is doing his math homework and he finds an equality on his text book: gcd( ...
最新文章
- 【SRM 716 DIV 1 A】 ConstructLCS
- 我的思维模式的阿喀琉斯之踵
- Mockito对final类型和方法的支持(三):免配置的inline mock making
- r语言默认工作目录document_使用 Docker 和 Nginx 实现简单目录索引服务
- 英雄联盟怎么解除小窗口_英雄联盟手游怎么加好友_英雄联盟手游怎么加好友一起玩_资讯...
- Oracle 的 Sql*Plus 常用命令介绍
- 【数据科学系统学习】机器学习算法 # 西瓜书学习记录 [8] 支持向量机(二)...
- wildfly access log 开启
- javascript 函数2——对象排序
- fft与fftshift的维度
- cc1101 使用笔记
- 电路串联和并联图解_判断串联并联电路图口诀
- 620集成显卡和mx250_MX250属于什么档次的显卡
- sin30的c语言表达式,c语言sin30度怎么打
- 8.2 知识蒸馏方法概述
- anaconda安装多环境
- 洛谷P3987 我永远喜欢珂朵莉~(set 树状数组)
- 有关C#中重写按钮的onpaint函数,实现按钮形状的用户自定义
- Windows时钟同步(时间同步)问题
- Gdal关于CAD转SHP格式