http://acm.hdu.edu.cn/showproblem.php?pid=3501

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4548    Accepted Submission(s): 1878

Problem Description
Given a positive integer N, your task is to calculate the sum of the positive integers less than N which are not coprime to N. A is said to be coprime to B if A, B share no common positive divisors except 1.
 
Input
For each test case, there is a line containing a positive integer N(1 ≤ N ≤ 1000000000). A line containing a single 0 follows the last test case.
 
Output
For each test case, you should print the sum module 1000000007 in a line.
 
Sample Input
3
4
0
 
Sample Output
0
2
 
Author
GTmac
 
Source
 
欧拉函数得和==phi(n)*n/2;
md 还是见识少。。
 #include <algorithm>
#include <cstdio> using namespace std; #define LL long long
const LL mod();
const LL N(+);
LL x; LL phi(LL x)
{
LL ret=;
for(LL i=;i*i<=x;i++)
if(x%i==)
{
x/=i;
ret*=i-;
for(;x%i==;)
ret*=i,x/=i;
}
if(x>) ret*=x-;
return ret;
} int main()
{
for(;scanf("%lld",&x)&&x;)
{
LL zz=(x-)*x>>;
printf("%lld\n",(zz-(x*phi(x)>>))%mod);
}
return ;
}

HDU——T 3501 Calculation 2的更多相关文章

  1. HDU 3501 Calculation 2(欧拉函数)

    Calculation 2 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submi ...

  2. HDU 3501 Calculation 2------欧拉函数变形

    Calculation 2 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  3. HDU 3501 Calculation 2 (欧拉函数)

    题目链接 题意 : 求小于n的数中与n不互质的所有数字之和. 思路 : 欧拉函数求的是小于等于n的数中与n互质的数个数,这个题的话,先把所有的数字之和求出来,再减掉欧拉函数中所有质数之和(即为eula ...

  4. hdu 3501 Calculation 2 (欧拉函数)

    题目 题意:求小于n并且 和n不互质的数的总和. 思路:求小于n并且与n互质的数的和为:n*phi[n]/2 . 若a和n互质,n-a必定也和n互质(a<n).也就是说num必定为偶数.其中互质 ...

  5. HDU 3501 Calculation 2

    题目大意:求小于n的与n不互质的数的和. 题解:首先欧拉函数可以求出小于n的与n互质的数的个数,然后我们可以发现这样一个性质,当x与n互质时,n-x与n互质,那么所有小于n与n互质的数总是可以两两配对 ...

  6. HDU 3501 Calculation 2 ——Dirichlet积

    [题目分析] 卷积太有趣了. 最终得出结论,互质数和为n*phi(n)/2即可. 计算(n*(n+1)/2-n-n*phi(n)/2)%md,用反正法即可证明. [代码] #include <c ...

  7. 题解报告:hdu 3501 Calculation 2 (欧拉函数的扩展)

    Description Given a positive integer N, your task is to calculate the sum of the positive integers l ...

  8. hdu 1202 The calculation of GPA

    感觉本题没有什么好解释的,已知公式,直接编程即可. 1.统计所有 科目的学分 得到总学分 2.统计所有 成绩对应的绩点*对应的学分即可(如果成绩==-1直接continue,不进行统计),得到总绩点. ...

  9. HDU更多的学校比赛9场 HDU 4965Fast Matrix Calculation【矩阵运算+数学技巧】

    困难,.,真,,,不是太困难 的问题是,有一个矩阵运算优化 您有权发言权N*K矩阵A给K*N矩阵B(1<=N<=1000 && 1=<K<=6).他们拿起了第一 ...

随机推荐

  1. javaScript 立即执行函数学习笔记

    立即执行函数: 即执行函数(Immediate Functions),立即执行函数模式是一种语法,可以让你的函数在定义后立即被执行 立即执行函数(immediate function)术语不是在ECM ...

  2. js垃圾回收机制理解

    原理 找到不再被使用的变量,然后释放其占用的内存,但这个过程不是时时的,因为其开销比较大, 所以垃圾回收器会按照固定时间间隔周期性的执行 回收方式 a.标记清除 当变量进入环境时,将这个变量标记为“进 ...

  3. js笔记3

    1字符串 replace("","")替换,前面为要替换什么,后面为替换的内容只能替换一个 2DOM 时间三要素 事件源 谁身上发生的行为 事件 单机 双击 事 ...

  4. Zabbix钉钉小机器人报警

    1.下载钉钉所需要的脚本golang-zabbix-robot-64,浏览器访问https://www.appgao.com/files/192.html: 图一    脚本下载 2.将脚本路径添加到 ...

  5. RocketMQ 就是耗内存

    http://blog.csdn.net/loongshawn/article/details/51086876 https://rocketmq.incubator.apache.org/docs/ ...

  6. Silverlight 应用程序中未处理的错误

    Silverlight 开发中遇到个错误: SCRIPT5022: Silverlight 应用程序中未处理的错误 代码: 2108 类别: InitializeError 消息: 无法下载初始屏幕或 ...

  7. 【Oracle】使用bbed恢复delete的数据

    表中的数据被delete之后并不会真正删除数据,而是打了一个删除标记,仅仅要还没有被覆盖就能够恢复回来. 实验步骤例如以下: SYS@ORCL>create table bbed_test(x  ...

  8. VC、IE、ASP环境下打印、预备的完美解决方式

    一种基于XML的报表开发工具,它支持从设计报表.调用API打印.预览,能支持分布式报表.方便报表的存储.转发. 在报表中能嵌入VBScript,能方便地訪问VB,VC的变量,能訪问COM组件.ADO等 ...

  9. js中Object.defineProperties 定义一个在原对象可读可写的方法

    function A(){ this.name = 'hellow word'; } Object.defineProperties( A.prototype,{ doSomething2 : { v ...

  10. hdu5400Arithmetic Sequence

    //一个序列,两个公差d1,d2 //问有多少个区间使得这个区间存在一个点,它的左边是公差为d1的序列 //它的右边是公差为d2的序列 //直接存入每一个点向左和向右延伸的公差长度,乘一下即可 //还 ...