HDU 3501 Calculation 2
题目大意:求小于n的与n不互质的数的和。
题解:首先欧拉函数可以求出小于n的与n互质的数的个数,然后我们可以发现这样一个性质,当x与n互质时,n-x与n互质,那么所有小于n与n互质的数总是可以两两配对使其和为n,这也就是为什么当n大于2时欧拉函数都是偶数,知道这一点后,就可以计算出小于n与n互质的数的和了,那么不互质的和只要用总和来减就可以了。
#include <cstdio>
typedef long long LL;
LL n,ans;
LL Eular(LL n){
LL ret=1;
for(int i=2;i*i<=n;i++){
if(n%i==0){
n/=i,ret*=(i-1);
while(n%i==0)n/=i,ret*=i;
}
}
if(n>1)ret*=(n-1);
return ret;
}
int main(){
while(~scanf("%lld",&n)&&n){
ans=n*(n+1)/2-n;
ans-=Eular(n)*n/2;
printf("%lld\n",ans%1000000007);
}return 0;
}
HDU 3501 Calculation 2的更多相关文章
- HDU 3501 Calculation 2(欧拉函数)
Calculation 2 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- HDU 3501 Calculation 2------欧拉函数变形
Calculation 2 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDU 3501 Calculation 2 (欧拉函数)
题目链接 题意 : 求小于n的数中与n不互质的所有数字之和. 思路 : 欧拉函数求的是小于等于n的数中与n互质的数个数,这个题的话,先把所有的数字之和求出来,再减掉欧拉函数中所有质数之和(即为eula ...
- hdu 3501 Calculation 2 (欧拉函数)
题目 题意:求小于n并且 和n不互质的数的总和. 思路:求小于n并且与n互质的数的和为:n*phi[n]/2 . 若a和n互质,n-a必定也和n互质(a<n).也就是说num必定为偶数.其中互质 ...
- HDU 3501 Calculation 2 ——Dirichlet积
[题目分析] 卷积太有趣了. 最终得出结论,互质数和为n*phi(n)/2即可. 计算(n*(n+1)/2-n-n*phi(n)/2)%md,用反正法即可证明. [代码] #include <c ...
- 题解报告:hdu 3501 Calculation 2 (欧拉函数的扩展)
Description Given a positive integer N, your task is to calculate the sum of the positive integers l ...
- HDU——T 3501 Calculation 2
http://acm.hdu.edu.cn/showproblem.php?pid=3501 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- Calculation 2 HDU - 3501
https://vjudge.net/problem/HDU-3501 不会做啊...记一下做法 做法是计算小于n且与n互质的数的和:根据如果gcd(i,n)==1,那么gcd(n-i,n)==1,对 ...
- C - Calculation 2 HDU - 3501 (欧拉)
Given a positive integer N, your task is to calculate the sum of the positive integers less than N w ...
随机推荐
- AutoCompleteTextview、MultiAutoCompleteTextView
AutoCompleteTextview 动态匹配输入内容文本框 属性: android:completionThreshold="2"; ...
- textarea 输入框限制字数
在textarea标签中,只需要设置maxlength=”***”即可,但是在textarea标签中,IE9及IE9以下浏览器是不支持的,IE10.IE11则支持,估计后续的版本应该都会支持. 现在来 ...
- 转: ES6异步编程: co函数库的含义与用法
转: ES6异步编程: co函数库的含义与用法 co 函数库是著名程序员 TJ Holowaychuk 于2013年6月发布的一个小工具,用于 Generator 函数的自动执行. 比如,有一个 Ge ...
- 無塵室(Clean Room)的級數標準規格
無塵室又稱潔淨室,是將一定空間範圍內空氣的微塵粒子.有害氣體.細菌等之污染物控制在一定的數量內.無塵室的等級是以一立方英呎含有多少大於0.5um的微塵粒子來定義的.下表是根據「美國聯邦標準209D規格 ...
- Cortex-M3学习日志(三)-- 外部中断0
无论是哪款单片机应该都有对应的中断的功能,中断在嵌入式系统的地位毋庸置疑.LPC1768微处理器包括4个外部中断,分别是EINT0.EINT1.EINT2.EINT3对应的引脚分别是P2.10~P2. ...
- MFC渐入渐出框实现方式二
类似360消息弹出框,实现方式一见http://blog.csdn.net/segen_jaa/article/details/7848598. 本文采用另外的API实现渐入渐出效果. 主要API:S ...
- nodejs项目中的路由写法
//两种路由写法,一种封装成函数,返回结果,此种方法可以传递参数, "use strict"; var _ = require("lodash"); var e ...
- location的用法
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- paip.c++ qt messagebox用法
paip.c++ qt messagebox用法 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn.net ...
- Deep Learning(深度学习)学习笔记整理系列之(四)
Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...