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
解题思路:求小于n且与n不互质的所有数之和,公式:n*(n-1)/2-n*Euler(n)/2。
AC代码:
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
#include <set>
using namespace std;
typedef long long LL;
const int maxn = 1e6+;
const LL mod = ;
LL n;
LL get_Euler(LL x){
LL res = x; ///初始值
for(LL i = 2LL; i * i <= x; ++i) {
if(x % i == ) {
res = res / i * (i - ); ///先除后乘,避免数据过大
while(x % i == ) x /= i;
}
}
if(x > 1LL) res = res / x * (x - ); ///若x大于1,则剩下的x必为素因子
return res;
} int main(){
while(cin >> n && n) {
cout << (n * (n - ) / - n * get_Euler(n) / ) % mod << endl;
}
return ;
}
 

题解报告:hdu 3501 Calculation 2 (欧拉函数的扩展)的更多相关文章

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

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

  2. hdu 3501 容斥原理或欧拉函数

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

  3. 题解报告:hdu 2588 GCD(欧拉函数)

    Description The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written ...

  4. HDU3501 Calculation 2 [欧拉函数]

    题目传送门 Calculation 2 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  5. HDU 5430 Reflect(欧拉函数)

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=5430 从镜面材质的圆上一点发出一道光线反射NNN次后首次回到起点. 问本质不同的发射的方案数. 输入描述 ...

  6. hdu 5279 Reflect phi 欧拉函数

    Reflect Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/contest_chi ...

  7. HDU 1695 GCD (欧拉函数+容斥原理)

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  8. HDU 1695 GCD(欧拉函数+容斥原理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1695 题意:x位于区间[a, b],y位于区间[c, d],求满足GCD(x, y) = k的(x, ...

  9. HDU 2588 GCD(欧拉函数)

    GCD Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  10. HDU 1787 GCD Again(欧拉函数,水题)

    GCD Again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

随机推荐

  1. How many ways?? 矩阵快速幂 邻接矩阵意义

    春天到了, HDU校园里开满了花, 姹紫嫣红, 非常美丽. 葱头是个爱花的人, 看着校花校草竞相开放, 漫步校园, 心情也变得舒畅. 为了多看看这迷人的校园, 葱头决定, 每次上课都走不同的路线去教室 ...

  2. Apache 使用localhost(127.0.0.1)可以访问,使用本机IP(局域网)不能访问

    本机ip是:192.168.1.25,输入后提示: Forbidden You don't have permission to access / on this server 对于此问题的解决办法, ...

  3. [bzoj3436]小K的农场_差分约束

    小K的农场 bzoj-3436 题目大意:给定n个点,每个节点有一个未知权值.现在有m个限制条件,形如:点i比点j至少大c,点i比点j至多大c或点i和点j相等.问是否可以通过给所有点赋值满足所有限制条 ...

  4. Oldboy 基于Linux的C/C++自动化开发---MYSQL

    http://www.eimhe.com/forum.php?mod=viewthread&tid=142952#lastpost http://www.eimhe.com/thread-14 ...

  5. mysql利用timestamp来进行帖子排序

    select * from table order by timestamp descorder by 该列 desc timestamp字段也可以用来排序,对应Java类型的.net.timesta ...

  6. 第三课 MongoDB 数据更新

    1.课程大纲 本课程主要解说 MongoDB 数据更新的相关内容.包含文档插入 insert 函数.文档删除 remove函数以及文档更新update函数的基本使用.除此之外.还会介绍 MongoDB ...

  7. Core Data 的简单使用

    认识cocoa Data在ios开发中的环境情况. watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/f ...

  8. Dell PowerEdge RAID Controller (PERC) | Dell

      Dell PowerEdge RAID Controller (PERC)             The Dell™ PERC (PowerEdge™ RAID Controller) fami ...

  9. centos 命令行中 * 和 . 的区别

    錯誤    cp /home/test1/* /home/test2/ –a          用參數*將不可以複製linux中.開頭的隱藏文件 正確    cp /home/test1/. home ...

  10. iOS开发项目实战——Swift实现图片轮播与浏览

    近期開始开发一个新的iOS应用,自己决定使用Swift.进行了几天之后,发现了一个非常严峻的问题.那就是无论是书籍,还是网络资源,关于Swift的实在是太少了,随便一搜全都是OC实现某某某功能.就算是 ...