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. PHP CURL HTTPS POST

    PHP CURL HTTPS POST function vpost($url,$data){ // 模拟提交数据函数    $curl = curl_init(); // 启动一个CURL会话    ...

  2. 编程里的API是什么意思?

    API(Application Programming Interface,应用程序编程接口)是一些预先定义的函数,目的是提供应用程序与开发人员基于某软件或硬件得以访问一组例程的能力,而又无需访问源码 ...

  3. vue 常用ui组件库

    vux github ui demo:https://github.com/airyland/vux Mint UI 项目主页:http://mint-ui.github.io/#!/zh-cn de ...

  4. 參考mudo logging写的win下logging

    #pragma once #include <boost/noncopyable.hpp> #include <boost/scoped_ptr.hpp> #include & ...

  5. UML类图中的几种关系总结

           UML类图,描写叙述对象和类之间相互关系的方式包含:依赖(Dependency).关联(Association).聚合(Aggregation).组合(Composition).泛化(G ...

  6. apicloud中的sqlite操作模块db

    db 模块封装了手机常用数据库 sqlite 的增删改查语句,可实现数据的本地存储,极大的简化了数据持久化问题. 1.执行 var db = api.require('db'); db.execute ...

  7. ElasticSearch 架构图

    ElasticSearch 架构图 从下往上来分析ElasticSearch 架构图 Gateway代表ElasticSearch索引的持久化存储方式. 在Gateway中,ElasticSearch ...

  8. private SortedDictionary<string, object> Dic_values = new SortedDictionary<string, object>();

    private SortedDictionary<string, object> Dic_values = new SortedDictionary<string, object&g ...

  9. 最大子段和 模板题 51Nod 1049

    N个整数组成的序列a[1],a[2],a[3],…,a[n],求该序列如a[i]+a[i+1]+…+a[j]的连续子段和的最大值.当所给的整数均为负数时和为0. 例如:-2,11,-4,13,-5,- ...

  10. 【Django】认证系统

    目录 #. auth模块 1. 认证 authenticate() 2. 登陆 login(HttpRequest, user) 3. 注销 logout(request) 4. 认证判断 is_au ...